Skip to content

Commit c6fed74

Browse files
authored
[diag] Silence -Wfixed-enum-extension in C23 (#68060)
The C23 standard supports enums with fixed underlying types (N3030 [1]), so we shouldn't emit `-Wfixed-enum-extension` in C23 mode (since it's no longer a Clang extension at that point). [1] https://thephd.dev/_vendor/future_cxx/papers/C%20-%20Enhanced%20Enumerations.html
1 parent 1129dec commit c6fed74

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ Improvements to Clang's diagnostics
219219
- Clang now displays an improved diagnostic and a note when a defaulted special
220220
member is marked ``constexpr`` in a class with a virtual base class
221221
(`#64843: <https://github.com/llvm/llvm-project/issues/64843>`_).
222+
- ``-Wfixed-enum-extension`` and ``-Wmicrosoft-fixed-enum`` diagnostics are no longer
223+
emitted when building as C23, since C23 standardizes support for enums with a
224+
fixed underlying type.
222225

223226
Bug Fixes in This Version
224227
-------------------------

clang/lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5009,7 +5009,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
50095009

50105010
BaseRange = SourceRange(ColonLoc, DeclaratorInfo.getSourceRange().getEnd());
50115011

5012-
if (!getLangOpts().ObjC) {
5012+
if (!getLangOpts().ObjC && !getLangOpts().C23) {
50135013
if (getLangOpts().CPlusPlus11)
50145014
Diag(ColonLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type)
50155015
<< BaseRange;

clang/test/Sema/fixed-enum.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
// RUN: %clang_cc1 -Weverything -std=c11 -xc -DC11 -verify %s
55
// RUN: %clang_cc1 -pedantic -std=c11 -xc -DC11 -verify %s
66
// RUN: %clang_cc1 -Weverything -std=c11 -xc -fms-extensions -DMS -verify %s
7+
// RUN: %clang_cc1 -Weverything -std=c2x -xc -DC23 -verify %s
8+
// RUN: %clang_cc1 -pedantic -std=c2x -xc -DC23 -verify %s
9+
// RUN: %clang_cc1 -Weverything -std=c23 -xc -DC23 -verify %s
10+
// RUN: %clang_cc1 -pedantic -std=c23 -xc -DC23 -verify %s
11+
// RUN: %clang_cc1 -Weverything -std=c23 -xc -fms-extensions -DC23 -verify %s
712

813
enum X : int {e};
914
#if defined(CXX11)
1015
// expected-warning@-2{{enumeration types with a fixed underlying type are incompatible with C++98}}
1116
#elif defined(CXX03)
1217
// expected-warning@-4{{enumeration types with a fixed underlying type are a C++11 extension}}
13-
#elif defined(OBJC)
18+
#elif defined(OBJC) || defined(C23)
1419
// No diagnostic
1520
#elif defined(C11)
1621
// expected-warning@-8{{enumeration types with a fixed underlying type are a Clang extension}}
@@ -21,19 +26,19 @@ enum X : int {e};
2126
// Don't warn about the forward declaration in any language mode.
2227
enum Fwd : int;
2328
enum Fwd : int { e2 };
24-
#ifndef OBJC
29+
#if !defined(OBJC) && !defined(C23)
2530
// expected-warning@-3 {{enumeration types with a fixed underlying type}}
2631
// expected-warning@-3 {{enumeration types with a fixed underlying type}}
2732
#endif
2833

2934
// Always error on the incompatible redeclaration.
3035
enum BadFwd : int;
31-
#ifndef OBJC
36+
#if !defined(OBJC) && !defined(C23)
3237
// expected-warning@-2 {{enumeration types with a fixed underlying type}}
3338
#endif
3439
// expected-note@-4 {{previous declaration is here}}
3540
enum BadFwd : char { e3 };
36-
#ifndef OBJC
41+
#if !defined(OBJC) && !defined(C23)
3742
// expected-warning@-2 {{enumeration types with a fixed underlying type}}
3843
#endif
3944
// expected-error@-4 {{enumeration redeclared with different underlying type 'char' (was 'int')}}

0 commit comments

Comments
 (0)