[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 25 04:10:17 PST 2024
================
@@ -121,6 +121,15 @@ int NegativeShortTest[NegativeShort == -1 ? 1 : -1];
enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
typedef struct Color NewColor; // expected-error {{use of 'Color' with tag type that does not match previous declaration}}
+// Enumerations with a fixed underlying type.
+// https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+ typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+ _Static_assert(__has_extension(c_fixed_enum), "Ensure language extension support for enumerations with a fixed underlying type in <C23");
+ typedef enum : unsigned char { Pink, Black, Cyan } Color; // expected-warning {{enumeration types with a fixed underlying type are a C23 extension}}
+#endif
----------------
Sirraide wrote:
```suggestion
#if __STDC_VERSION__ >= 202311L && !__has_extension(c_fixed_enum)
# error c_fixed_enum should be set in C23 mode
#else
typedef enum : unsigned char { Pink, Black, Cyan } Color; // pre-c23-warning {{enumeration types with a fixed underlying type are a C23 extension}}
```
I think we usually test these via the preprocessor.
https://github.com/llvm/llvm-project/pull/117507
More information about the cfe-commits
mailing list