Skip to content

Conversation

MilkeeyCat
Copy link
Contributor

I added new options as mentioned in the issue, do you think there should also be one more option for constexpr class member?

closes #54110

@llvmbot
Copy link
Member

llvmbot commented Oct 6, 2025

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Alex White (MilkeeyCat)

Changes

I added new options as mentioned in the issue, do you think there should also be one more option for constexpr class member?

closes #54110


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

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp (+16-2)
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5178bee5c3374..1b6f7117ddc4d 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -83,14 +83,17 @@ namespace readability {
     m(Member) \
     m(ClassConstant) \
     m(ClassMember) \
+    m(ConstexprGlobalVariable) \
     m(GlobalConstant) \
     m(GlobalConstantPointer) \
     m(GlobalPointer) \
     m(GlobalVariable) \
+    m(ConstexprLocalVariable) \
     m(LocalConstant) \
     m(LocalConstantPointer) \
     m(LocalPointer) \
     m(LocalVariable) \
+    m(ConstexprStaticVariable) \
     m(StaticConstant) \
     m(StaticVariable) \
     m(Constant) \
@@ -1497,8 +1500,19 @@ StyleKind IdentifierNamingCheck::findStyleKindForField(
 StyleKind IdentifierNamingCheck::findStyleKindForVar(
     const VarDecl *Var, QualType Type,
     ArrayRef<std::optional<NamingStyle>> NamingStyles) const {
-  if (Var->isConstexpr() && NamingStyles[SK_ConstexprVariable])
-    return SK_ConstexprVariable;
+  if (Var->isConstexpr()) {
+    if (Var->isFileVarDecl() && NamingStyles[SK_ConstexprGlobalVariable])
+      return SK_ConstexprGlobalVariable;
+
+    if (Var->isStaticLocal() && NamingStyles[SK_ConstexprStaticVariable])
+      return SK_ConstexprStaticVariable;
+
+    if (Var->isLocalVarDecl() && NamingStyles[SK_ConstexprLocalVariable])
+      return SK_ConstexprLocalVariable;
+
+    if (NamingStyles[SK_ConstexprVariable])
+      return SK_ConstexprVariable;
+  }
 
   if (!Type.isNull() && Type.isConstQualified()) {
     if (Var->isStaticDataMember() && NamingStyles[SK_ClassConstant])

@MilkeeyCat
Copy link
Contributor Author

@HerrCai0907 @PiotrZSL

@vbvictor
Copy link
Contributor

vbvictor commented Oct 6, 2025

Please add: release notes, tests.
See other PRs with clang-tidy tag for reference

@EugeneZelenko
Copy link
Contributor

Please mention changes in Release Notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

readability-identifier-naming needs to differentiate constexpr variables
4 participants