Debian Codegraph @

gcc/testsuite/gcc.dg/c23-enum-4.c

raw
1 /* Test C23 enumerations with values not representable in int. Test overflow
2 of __int128 is diagnosed. */
3 /* { dg-do compile { target { int128 } } } */
4 /* { dg-options "-std=c23" } */
5
6 enum e1 { e1a = (__int128) (((unsigned __int128) -1) >> 1), e1b }; /* { dg-error "overflow in enumeration values" } */
7
8 enum e2 { e2a = (unsigned __int128) -1, e2b }; /* { dg-error "overflow in enumeration values" } */
9
10 /* Likewise, when it's the enum as a whole that can't fit in __int128 or
11 unsigned __int128, but the individual enumerators fit (some fitting __int128
12 and some fitting unsigned __int128). */
13 enum e3 { e3a = -(__int128) (((unsigned __int128) -1) >> 1) - 1,
14 e3b = (unsigned __int128) -1 }; /* { dg-warning "enumeration values exceed range of largest integer" } */