diff options
author | Michael Forney <mforney@mforney.org> | 2024-03-21 16:43:00 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2024-03-21 17:33:40 -0700 |
commit | d1d23429f5dc3d78b03b318a7d349ad71a6c97fa (patch) | |
tree | 072e44175ebd75970565e9eb3b893bada3bbdd2a /test/enum-fixed.c | |
parent | 8bed97beaea3839369a947ea741aa083e76ca014 (diff) |
decl: Add support for enums with large values and fixed underlying types
Fixes: https://todo.sr.ht/~mcf/cproc/64
Diffstat (limited to 'test/enum-fixed.c')
-rw-r--r-- | test/enum-fixed.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/enum-fixed.c b/test/enum-fixed.c new file mode 100644 index 0000000..9ac85ca --- /dev/null +++ b/test/enum-fixed.c @@ -0,0 +1,36 @@ +enum E1 : short; +_Static_assert(__builtin_types_compatible_p(enum E1, short)); + +enum E2 : unsigned short { + A2 = 0x7fff, + B2, + A2type = __builtin_types_compatible_p(typeof(A2), unsigned short), + B2type = __builtin_types_compatible_p(typeof(B2), unsigned short), +}; +_Static_assert(__builtin_types_compatible_p(typeof(A2), unsigned short)); +_Static_assert(A2type == 1); +_Static_assert(__builtin_types_compatible_p(typeof(B2), unsigned short)); +_Static_assert(B2type == 1); +_Static_assert(__builtin_types_compatible_p(enum E2, unsigned short)); + +enum E3 : long long { + A3, + B3, + A3type = __builtin_types_compatible_p(typeof(A3), long long), + B3type = __builtin_types_compatible_p(typeof(B3), long long), +}; +_Static_assert(__builtin_types_compatible_p(typeof(A3), long long)); +_Static_assert(A3type == 1); +_Static_assert(__builtin_types_compatible_p(typeof(B3), long long)); +_Static_assert(B3type == 1); +_Static_assert(__builtin_types_compatible_p(enum E3, long long)); + +enum E4 : long long { + A4 = sizeof(enum E4), + A4type1 = __builtin_types_compatible_p(typeof(A4), enum E4), + A4type2 = !__builtin_types_compatible_p(typeof(A4), enum E3), +}; +_Static_assert(__builtin_types_compatible_p(typeof(A4), enum E4)); +_Static_assert(A4type1 == 1); +_Static_assert(!__builtin_types_compatible_p(typeof(A4), enum E3)); +_Static_assert(A4type2 == 1); |