Skip to content

Conversation

@shafik
Copy link
Collaborator

@shafik shafik commented Jun 11, 2025

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.

…tOnEnumConstant

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.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 11, 2025

@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)

Changes

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.


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

1 Files Affected:

  • (modified) clang/lib/Sema/SemaDecl.cpp (+4-3)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index bbd63372c168b..cfb58e33980d2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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;
 
   EnumConstantDecl *New =
     CheckEnumConstant(TheEnumDecl, LastEnumConst, IdLoc, Id, Val);

@shafik shafik merged commit f874092 into llvm:main Aug 16, 2025
9 checks passed
@shafik shafik deleted the ActOnEnumConstantCheckDiagnoseClassNameShadow branch August 17, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants