Skip to content

Commit 9ef0a88

Browse files
authored
[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 }; }; ```
1 parent 4453792 commit 9ef0a88

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,10 @@ Bug Fixes in This Version
776776
- In C23, something like ``[[/*possible attributes*/]];`` is an attribute
777777
declaration, not a statement. So it is not allowed by the syntax in places
778778
where a statement is required, specifically as the secondary block of a
779-
selection or iteration statement. This differs from C++, since C++ allows
779+
selection or iteration statement. This differs from C++, since C++ allows
780780
declaration statements. Clang now emits a warning for these patterns. (#GH141659)
781+
- Fixed false positives for redeclaration errors of using enum in
782+
nested scopes. (#GH147495)
781783

782784
Bug Fixes to Compiler Builtins
783785
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13308,7 +13308,7 @@ NamedDecl *Sema::BuildUsingEnumDeclaration(Scope *S, AccessSpecifier AS,
1330813308
LookupResult Previous(*this, UsingEnumName, LookupUsingDeclName,
1330913309
RedeclarationKind::ForVisibleRedeclaration);
1331013310

13311-
LookupName(Previous, S);
13311+
LookupQualifiedName(Previous, CurContext);
1331213312

1331313313
for (NamedDecl *D : Previous)
1331413314
if (UsingEnumDecl *UED = dyn_cast<UsingEnumDecl>(D))

clang/test/SemaCXX/cxx20-using-enum.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,18 @@ void f(int a) {
274274
}
275275
}
276276

277+
namespace GH147495 {
278+
struct S {
279+
enum class E { A };
280+
using enum E;
281+
282+
struct S1 {
283+
using enum E;
284+
};
285+
286+
struct S2 {
287+
using E::A;
288+
};
289+
};
290+
}
277291
#endif

0 commit comments

Comments
 (0)