1 /* $NetBSD: decl_enum.c,v 1.3 2022/04/16 09:22:25 rillig Exp $ */ 2 # 3 "decl_enum.c" 3 4 /* 5 * Tests for enum declarations. 6 */ 7 8 /* cover 'enumerator_list: error' */ 9 enum { 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] */ 16 enum 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 */ 28 enum 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] */ 49 typedef int reveal_i1[-i1]; 50 /* expect+1: error: negative array dimension (-10001) [20] */ 51 typedef int reveal_i2[-i2]; 52 /* expect+1: error: negative array dimension (-10002) [20] */ 53 typedef int reveal_i3[-i3]; 54 55 /* expect+1: error: negative array dimension (-4) [20] */ 56 typedef int reveal_o1[-o1]; 57 /* expect+1: error: negative array dimension (-5) [20] */ 58 typedef int reveal_o2[-o2]; 59 /* expect+1: error: negative array dimension (-10002) [20] */ 60 typedef int reveal_o3[-o3]; 61 62 /* Since C99, a trailing comma is allowed in an enum declaration. */ 63 enum trailing_comma { 64 constant, 65 }; 66