Skip to content

Commit cfb86ae

Browse files
authored
[Clang][Sema] Skip checking anonymous enum in using enum declaration (llvm#87144)
Try to fix llvm#86790 `getFETokenInfo` requires `DeclarationName` shouldn't be empty and this will produce crash when checking name conflict of an anonymous `NamedDecl` in `Sema::PushOnScopeChains` and whether it's a reserved identifier or not. These wouldn't happen when it's a anonymous enum and we can skip the checking and just add the declaration to current scope. Co-authored-by: huqizhi <[email protected]>
1 parent ef8322f commit cfb86ae

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ Bug Fixes to C++ Support
503503

504504
- Fix crash when inheriting from a cv-qualified type. Fixes:
505505
(`#35603 <https://github.com/llvm/llvm-project/issues/35603>`_)
506+
- Fix a crash when the using enum declaration uses an anonymous enumeration. Fixes (#GH86790).
506507

507508
Bug Fixes to AST Handling
508509
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,10 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext) {
15371537
cast<FunctionDecl>(D)->isFunctionTemplateSpecialization())
15381538
return;
15391539

1540+
if (isa<UsingEnumDecl>(D) && D->getDeclName().isEmpty()) {
1541+
S->AddDecl(D);
1542+
return;
1543+
}
15401544
// If this replaces anything in the current scope,
15411545
IdentifierResolver::iterator I = IdResolver.begin(D->getDeclName()),
15421546
IEnd = IdResolver.end();

clang/test/SemaCXX/PR86790.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
2+
3+
enum {A, S, D, F};
4+
int main() {
5+
using asdf = decltype(A);
6+
using enum asdf; // this line causes the crash
7+
return 0;
8+
}
9+
10+
namespace N1 {
11+
enum {A, S, D, F};
12+
constexpr struct T {
13+
using asdf = decltype(A);
14+
using enum asdf;
15+
} t;
16+
17+
static_assert(t.D == D);
18+
static_assert(T::S == S);
19+
}
20+
21+
namespace N2 {
22+
enum {A, S, D, F};
23+
constexpr struct T {
24+
struct {
25+
using asdf = decltype(A);
26+
using enum asdf;
27+
} inner;
28+
} t;
29+
30+
static_assert(t.inner.D == D);
31+
static_assert(t.D == D); // expected-error {{no member named 'D' in 'N2::T'}}
32+
}

0 commit comments

Comments
 (0)