Skip to content

Commit 6af2c18

Browse files
authored
[clang] fix regression parsing C enum which doesn't declare anything (#155904)
The regression was introduced in #155313 Since this regression was never released, there are no release notes. Fixes #155794
1 parent a4ac04d commit 6af2c18

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5291,10 +5291,8 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
52915291
// UNION_TYPE; <- where UNION_TYPE is a typedef union.
52925292
if ((Tag && Tag->getDeclName()) ||
52935293
DS.getTypeSpecType() == DeclSpec::TST_typename) {
5294-
RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Tag);
5295-
if (!Record)
5296-
Record = DS.getRepAsType().get()->getAsRecordDecl();
5297-
5294+
RecordDecl *Record = Tag ? dyn_cast<RecordDecl>(Tag)
5295+
: DS.getRepAsType().get()->getAsRecordDecl();
52985296
if (Record && getLangOpts().MicrosoftExt) {
52995297
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
53005298
<< Record->isUnion() << DS.getSourceRange();

clang/test/Sema/GH155794.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-everything %s
2+
3+
struct S {
4+
enum e1 {} // expected-error {{use of empty enum}} expected-error {{expected ';' after enum}}
5+
enum e2 {} // expected-error {{use of empty enum}}
6+
}; // expected-error {{expected member name or ';' after declaration specifiers}}

0 commit comments

Comments
 (0)