[clang] [Clang][Sema] Check the return value of DiagnoseClassNameShadow in ActOnEnumConstant (PR #143754)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 11 11:31:19 PDT 2025


================
@@ -20134,9 +20134,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;
----------------
AaronBallman wrote:

Perhaps a test case could be added along the lines of:
```
struct S {
  static constexpr enum E {
    S = 12
  } e = S;
  static_assert(e == S);
  static_assert(S == 12);
};
```
I believe the existing code passes because we diagnose the shadow but then go ahead and make an enumerator with the class name, and oofda is that confusing: https://godbolt.org/z/K4c83frMh

https://github.com/llvm/llvm-project/pull/143754


More information about the cfe-commits mailing list