decl_enum.c revision 1.2
1/*	$NetBSD: decl_enum.c,v 1.2 2022/04/08 21:29:29 rillig Exp $	*/
2# 3 "decl_enum.c"
3
4/*
5 * Tests for enum declarations.
6 */
7
8/* cover 'enumerator_list: error' */
9enum {
10	/* expect+1: error: syntax error 'goto' [249] */
11	goto
12};
13
14/* cover 'enum_specifier: enum error' */
15/* expect+1: error: syntax error 'goto' [249] */
16enum goto {
17	A
18};
19/* expect-1: warning: empty declaration [0] */
20
21
22/*
23 * Ensure that nested enum declarations get the value of each enum constant
24 * right.  The variable containing the "current enum value" does not account
25 * for these nested declarations.  Such declarations don't occur in practice
26 * though.
27 */
28enum outer {
29	o1 = sizeof(
30	    enum inner {
31		    i1 = 10000, i2, i3
32	    }
33	),
34	/*
35	 * The only attribute that GCC 12 allows for enum constants is
36	 * __deprecated__, and there is no way to smuggle an integer constant
37	 * expression into the attribute.  If there were a way, and the
38	 * expression contained an enum declaration, the value of the outer
39	 * enum constant would become the value of the last seen inner enum
40	 * constant.  This is because 'enumval' is a simple scalar variable,
41	 * not a stack.  If it should ever become necessary to account for
42	 * nested enum declarations, a field should be added in dinfo_t.
43	 */
44	o2 __attribute__((__deprecated__)),
45	o3 = i3
46};
47
48/* expect+1: error: negative array dimension (-10000) [20] */
49typedef int reveal_i1[-i1];
50/* expect+1: error: negative array dimension (-10001) [20] */
51typedef int reveal_i2[-i2];
52/* expect+1: error: negative array dimension (-10002) [20] */
53typedef int reveal_i3[-i3];
54
55/* expect+1: error: negative array dimension (-4) [20] */
56typedef int reveal_o1[-o1];
57/* expect+1: error: negative array dimension (-5) [20] */
58typedef int reveal_o2[-o2];
59/* expect+1: error: negative array dimension (-10002) [20] */
60typedef int reveal_o3[-o3];
61