Author: Oleksandr T. Date: 2025-07-10T18:13:44+03:00 New Revision: 9ef0a886e621eb4202f82054983c383fa82aff9a
URL: https://github.com/llvm/llvm-project/commit/9ef0a886e621eb4202f82054983c383fa82aff9a DIFF: https://github.com/llvm/llvm-project/commit/9ef0a886e621eb4202f82054983c383fa82aff9a.diff LOG: [Clang] fixed false positive redeclaration error for using enum in nested scopes (#147711) Fixes #147495 --- This patch addresses the issue of false-positive redeclaration errors that occur for `using enum` declarations in nested class scopes ```cpp struct S { enum class E { A }; using enum E; struct S1 { using enum E; // no error }; }; ``` Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaDeclCXX.cpp clang/test/SemaCXX/cxx20-using-enum.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ca00a80d10eca..b6af43c062013 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -776,8 +776,10 @@ Bug Fixes in This Version - In C23, something like ``[[/*possible attributes*/]];`` is an attribute declaration, not a statement. So it is not allowed by the syntax in places where a statement is required, specifically as the secondary block of a - selection or iteration statement. This diff ers from C++, since C++ allows + selection or iteration statement. This diff ers from C++, since C++ allows declaration statements. Clang now emits a warning for these patterns. (#GH141659) +- Fixed false positives for redeclaration errors of using enum in + nested scopes. (#GH147495) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index a49a8abb677c5..5cc92ebb0171f 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -13308,7 +13308,7 @@ NamedDecl *Sema::BuildUsingEnumDeclaration(Scope *S, AccessSpecifier AS, LookupResult Previous(*this, UsingEnumName, LookupUsingDeclName, RedeclarationKind::ForVisibleRedeclaration); - LookupName(Previous, S); + LookupQualifiedName(Previous, CurContext); for (NamedDecl *D : Previous) if (UsingEnumDecl *UED = dyn_cast<UsingEnumDecl>(D)) diff --git a/clang/test/SemaCXX/cxx20-using-enum.cpp b/clang/test/SemaCXX/cxx20-using-enum.cpp index 14ef4b29925a1..775b65c5a8d8e 100644 --- a/clang/test/SemaCXX/cxx20-using-enum.cpp +++ b/clang/test/SemaCXX/cxx20-using-enum.cpp @@ -274,4 +274,18 @@ void f(int a) { } } +namespace GH147495 { +struct S { + enum class E { A }; + using enum E; + + struct S1 { + using enum E; + }; + + struct S2 { + using E::A; + }; +}; +} #endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits