decl_enum.c revision 1.3
11.3Srillig/* $NetBSD: decl_enum.c,v 1.3 2022/04/16 09:22:25 rillig Exp $ */ 21.1Srillig# 3 "decl_enum.c" 31.1Srillig 41.1Srillig/* 51.1Srillig * Tests for enum declarations. 61.1Srillig */ 71.1Srillig 81.1Srillig/* cover 'enumerator_list: error' */ 91.1Srilligenum { 101.1Srillig /* expect+1: error: syntax error 'goto' [249] */ 111.1Srillig goto 121.1Srillig}; 131.1Srillig 141.1Srillig/* cover 'enum_specifier: enum error' */ 151.1Srillig/* expect+1: error: syntax error 'goto' [249] */ 161.1Srilligenum goto { 171.1Srillig A 181.1Srillig}; 191.1Srillig/* expect-1: warning: empty declaration [0] */ 201.2Srillig 211.2Srillig 221.2Srillig/* 231.2Srillig * Ensure that nested enum declarations get the value of each enum constant 241.2Srillig * right. The variable containing the "current enum value" does not account 251.2Srillig * for these nested declarations. Such declarations don't occur in practice 261.2Srillig * though. 271.2Srillig */ 281.2Srilligenum outer { 291.2Srillig o1 = sizeof( 301.2Srillig enum inner { 311.2Srillig i1 = 10000, i2, i3 321.2Srillig } 331.2Srillig ), 341.2Srillig /* 351.2Srillig * The only attribute that GCC 12 allows for enum constants is 361.2Srillig * __deprecated__, and there is no way to smuggle an integer constant 371.2Srillig * expression into the attribute. If there were a way, and the 381.2Srillig * expression contained an enum declaration, the value of the outer 391.2Srillig * enum constant would become the value of the last seen inner enum 401.2Srillig * constant. This is because 'enumval' is a simple scalar variable, 411.2Srillig * not a stack. If it should ever become necessary to account for 421.2Srillig * nested enum declarations, a field should be added in dinfo_t. 431.2Srillig */ 441.2Srillig o2 __attribute__((__deprecated__)), 451.2Srillig o3 = i3 461.2Srillig}; 471.2Srillig 481.2Srillig/* expect+1: error: negative array dimension (-10000) [20] */ 491.2Srilligtypedef int reveal_i1[-i1]; 501.2Srillig/* expect+1: error: negative array dimension (-10001) [20] */ 511.2Srilligtypedef int reveal_i2[-i2]; 521.2Srillig/* expect+1: error: negative array dimension (-10002) [20] */ 531.2Srilligtypedef int reveal_i3[-i3]; 541.2Srillig 551.2Srillig/* expect+1: error: negative array dimension (-4) [20] */ 561.2Srilligtypedef int reveal_o1[-o1]; 571.2Srillig/* expect+1: error: negative array dimension (-5) [20] */ 581.2Srilligtypedef int reveal_o2[-o2]; 591.2Srillig/* expect+1: error: negative array dimension (-10002) [20] */ 601.2Srilligtypedef int reveal_o3[-o3]; 611.3Srillig 621.3Srillig/* Since C99, a trailing comma is allowed in an enum declaration. */ 631.3Srilligenum trailing_comma { 641.3Srillig constant, 651.3Srillig}; 66