Skip to content

Commit d9e0615

Browse files
author
Aidan
committed
Updated Features.def to include c_fixed_enum. Updated enum.c test to check for support of enums with a fixed underlying type in C23 and <C23.
1 parent a6c9b5c commit d9e0615

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang/include/clang/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ FEATURE(objc_arc_fields, true)
131131
FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
132132
FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
133133
FEATURE(objc_fixed_enum, LangOpts.ObjC)
134+
FEATURE(c_fixed_enum, true)
134135
FEATURE(objc_instancetype, LangOpts.ObjC)
135136
FEATURE(objc_kindof, LangOpts.ObjC)
136137
FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)

clang/test/Sema/enum.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ int NegativeShortTest[NegativeShort == -1 ? 1 : -1];
121121
enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
122122
typedef struct Color NewColor; // expected-error {{use of 'Color' with tag type that does not match previous declaration}}
123123

124+
// Enumerations with a fixed underlying type.
125+
// https://github.com/llvm/llvm-project/issues/116880
126+
#if __STDC_VERSION__ >= 202311L
127+
typedef enum : unsigned char { Pink, Black, Cyan } Color;
128+
#else
129+
_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension support for enumerations with a fixed underlying type in <C23");
130+
typedef enum : unsigned char { Pink, Black, Cyan } Color; // expected-warning {{enumeration types with a fixed underlying type are a C23 extension}}
131+
#endif
132+
133+
134+
124135
// PR28903
125136
// In C it is valid to define tags inside enums.
126137
struct PR28903 {
@@ -174,6 +185,7 @@ enum IncOverflow {
174185
V3 // pre-c23-warning {{incremented enumerator value which exceeds the range of 'int' is a C23 extension}}
175186
};
176187

188+
177189
#if __STDC_VERSION__ >= 202311L
178190
// FIXME: GCC picks __uint128_t as the underlying type for the enumeration
179191
// value and Clang picks unsigned long long.

0 commit comments

Comments
 (0)