[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.
This commit is contained in:
Shafik Yaghmour 2025-08-16 14:08:39 -07:00 committed by GitHub
parent ddae3b74a3
commit f8740920ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View File

@ -20270,9 +20270,10 @@ Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, Decl *lastEnumConst,
// different from T:
// - every enumerator of every member of class T that is an unscoped
// enumerated type
if (getLangOpts().CPlusPlus && !TheEnumDecl->isScoped())
DiagnoseClassNameShadow(TheEnumDecl->getDeclContext(),
DeclarationNameInfo(Id, IdLoc));
if (getLangOpts().CPlusPlus && !TheEnumDecl->isScoped() &&
DiagnoseClassNameShadow(TheEnumDecl->getDeclContext(),
DeclarationNameInfo(Id, IdLoc)))
return nullptr;
EnumConstantDecl *New =
CheckEnumConstant(TheEnumDecl, LastEnumConst, IdLoc, Id, Val);

View File

@ -114,3 +114,12 @@ template<typename B> struct CtorDtorName : B {
CtorDtorName();
~CtorDtorName(); // expected-error {{identifier 'CtorDtorName' after '~' in destructor name does not name a type}}
};
struct S { // expected-note {{'S' declared here}}
enum E {
R = 11,
S = 12 // expected-error {{member 'S' has the same name as its class}}
};
static_assert(E::R == 11, "E::R is not 11");
static_assert(E::S == 12, "E::S is not 12"); // expected-error {{no member named 'S' in 'S::E'}}
};