Skip to content

Commit f874092

Browse files
authored
[Clang][Sema] Check the return value of DiagnoseClassNameShadow in ActOnEnumConstant (#143754)
Static analysis flagged that we were not checking the return value of DiagnoseClassNameShadow when we did so everywhere else. Modifying this case to match how other places uses it makes sense and does not change behavior. Likely if this check fails later actions will fail as well but it is more correct to exit early.
1 parent ddae3b7 commit f874092

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20270,9 +20270,10 @@ Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, Decl *lastEnumConst,
2027020270
// different from T:
2027120271
// - every enumerator of every member of class T that is an unscoped
2027220272
// enumerated type
20273-
if (getLangOpts().CPlusPlus && !TheEnumDecl->isScoped())
20274-
DiagnoseClassNameShadow(TheEnumDecl->getDeclContext(),
20275-
DeclarationNameInfo(Id, IdLoc));
20273+
if (getLangOpts().CPlusPlus && !TheEnumDecl->isScoped() &&
20274+
DiagnoseClassNameShadow(TheEnumDecl->getDeclContext(),
20275+
DeclarationNameInfo(Id, IdLoc)))
20276+
return nullptr;
2027620277

2027720278
EnumConstantDecl *New =
2027820279
CheckEnumConstant(TheEnumDecl, LastEnumConst, IdLoc, Id, Val);

clang/test/CXX/class/class.mem/p13.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,12 @@ template<typename B> struct CtorDtorName : B {
114114
CtorDtorName();
115115
~CtorDtorName(); // expected-error {{identifier 'CtorDtorName' after '~' in destructor name does not name a type}}
116116
};
117+
118+
struct S { // expected-note {{'S' declared here}}
119+
enum E {
120+
R = 11,
121+
S = 12 // expected-error {{member 'S' has the same name as its class}}
122+
};
123+
static_assert(E::R == 11, "E::R is not 11");
124+
static_assert(E::S == 12, "E::S is not 12"); // expected-error {{no member named 'S' in 'S::E'}}
125+
};

0 commit comments

Comments
 (0)