[clang] [Clang] fixed false positive redeclaration error for using enum in nested scopes (PR #147711)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 9 05:19:21 PDT 2025
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/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
};
};
```
>From 20b9d9bb16f82120cee41bf6a59d3bfa34aa0d3b Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk <oleksandr.tarasiuk at outlook.com>
Date: Wed, 9 Jul 2025 15:16:45 +0300
Subject: [PATCH] [Clang] fixed false positive redeclaration error for using
enum in nested scopes
---
clang/docs/ReleaseNotes.rst | 4 +++-
clang/lib/Sema/SemaDeclCXX.cpp | 2 +-
clang/test/SemaCXX/cxx20-using-enum.cpp | 14 ++++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 57a94242c9e61..086f0fce4975f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -770,8 +770,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 differs from C++, since C++ allows
+ selection or iteration statement. This differs 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
More information about the cfe-commits
mailing list