[clang] [Clang][Sema] Skip checking anonymous enum in using enum declaration (PR #87144)

Qizhi Hu via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 30 00:02:10 PDT 2024


https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/87144

Try to fix https://github.com/llvm/llvm-project/issues/86790
Skip checking anonymous enumeration in using enum declaration.

>From bff555ed0466a74a4e23d7d4feca2940ee04b719 Mon Sep 17 00:00:00 2001
From: huqizhi <huqizhi at feysh.com>
Date: Sat, 30 Mar 2024 14:47:00 +0800
Subject: [PATCH] [Clang][Sema] Skip checking anonymous enum in using enum
 declaration

---
 clang/docs/ReleaseNotes.rst    | 1 +
 clang/lib/Sema/SemaDecl.cpp    | 4 ++++
 clang/test/SemaCXX/PR86790.cpp | 9 +++++++++
 3 files changed, 14 insertions(+)
 create mode 100644 clang/test/SemaCXX/PR86790.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 232de0d7d8bb73..39f896652d03d5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -459,6 +459,7 @@ Bug Fixes to C++ Support
   following the first `::` were ignored).
 - Fix an out-of-bounds crash when checking the validity of template partial specializations. (part of #GH86757).
 - Fix an issue caused by not handling invalid cases when substituting into the parameter mapping of a constraint. Fixes (#GH86757).
+- Fix a crash when the using enum declaration uses an anonymous enumeration. Fixes (#GH86790).
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0bd88ece2aa544..dda0b08d93bc75 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1537,6 +1537,10 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext) {
       cast<FunctionDecl>(D)->isFunctionTemplateSpecialization())
     return;
 
+  if (isa<EnumDecl>(D) && D->getDeclName().isEmpty()) {
+    S->AddDecl(D);
+    return;
+  }
   // If this replaces anything in the current scope,
   IdentifierResolver::iterator I = IdResolver.begin(D->getDeclName()),
                                IEnd = IdResolver.end();
diff --git a/clang/test/SemaCXX/PR86790.cpp b/clang/test/SemaCXX/PR86790.cpp
new file mode 100644
index 00000000000000..65403baea32c01
--- /dev/null
+++ b/clang/test/SemaCXX/PR86790.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+// expected-no-diagnostics
+
+enum {A, S, D, F};
+int main() {
+    using asdf = decltype(A);
+    using enum asdf; // this line causes the crash
+    return 0;
+}
\ No newline at end of file



More information about the cfe-commits mailing list