Skip to content

Commit 967137c

Browse files
committed
No longer accept scoped enumerations in C
We had a think-o that would allow a user to declare a scoped enumeration in C language modes "as a C++11 extension". This is a think-o because there's no way for the user to spell the name of the enumerators; C does not have '::' for a fully-qualified name. See commit d0d87b5 for details on why this is unintentional for C. Fixes #42372
1 parent 7e71a03 commit 967137c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ Bug Fixes
142142
- Fixed a false positive diagnostic about an unevaluated expression having no
143143
side effects when the expression is of VLA type and is an operand of the
144144
``sizeof`` operator. Fixes `Issue 48010 <https://github.com/llvm/llvm-project/issues/48010>`_.
145+
- Fixed a false positive diagnostic about scoped enumerations being a C++11
146+
extension in C mode. A scoped enumeration's enumerators cannot be named in C
147+
because there is no way to fully qualify the enumerator name, so this
148+
"extension" was unintentional and useless. This fixes
149+
`Issue 42372 <https://github.com/llvm/llvm-project/issues/42372>`_.
145150

146151
Improvements to Clang's diagnostics
147152
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4531,7 +4531,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
45314531
bool IsScopedUsingClassTag = false;
45324532

45334533
// In C++11, recognize 'enum class' and 'enum struct'.
4534-
if (Tok.isOneOf(tok::kw_class, tok::kw_struct)) {
4534+
if (Tok.isOneOf(tok::kw_class, tok::kw_struct) && getLangOpts().CPlusPlus) {
45354535
Diag(Tok, getLangOpts().CPlusPlus11 ? diag::warn_cxx98_compat_scoped_enum
45364536
: diag::ext_scoped_enum);
45374537
IsScopedUsingClassTag = Tok.is(tok::kw_class);

clang/test/Sema/enum.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,16 @@ struct EnumRedeclStruct {
159159
PR15071_One // expected-error {{redefinition of enumerator 'PR15071_One'}}
160160
} e;
161161
};
162+
163+
enum struct GH42372_1 { // expected-error {{expected identifier or '{'}} expected-warning {{declaration does not declare anything}}
164+
One
165+
};
166+
167+
// Because class is not a keyword in C, this looks like a forward declaration.
168+
// expected-error@+4 {{expected ';' after top level declarator}}
169+
// expected-error@+3 {{tentative definition has type 'enum class' that is never completed}}
170+
// expected-warning@+2 {{ISO C forbids forward references to 'enum' types}}
171+
// expected-note@+1 {{forward declaration of 'enum class'}}
172+
enum class GH42372_2 {
173+
One
174+
};

0 commit comments

Comments
 (0)