-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-tidy] Add more constexpr options to readability-identifier-naming
#162160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Alex White (MilkeeyCat) ChangesI 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:
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])
|
Please add: release notes, tests. |
Please mention changes in Release Notes. |
I'll change Release Notes and add test cases soon, but I can't decide how should the options be called, is it |
I prefer |
@HerrCai0907 a constexpr is const so it does not change. A variable means it can vary. Isn't it contradicting then to say a constant variable ( |
b5c241d
to
3a2ce43
Compare
I made option descriptions using other options, but some sentences make no sense or are not clear/correct :\ llvm-project/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst Lines 960 to 961 in 86ad98c
llvm-project/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst Lines 960 to 961 in 86ad98c
Doesn't it check whether the name has the suffix? |
From correctness perspective, maybe llvm-project/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst Lines 801 to 804 in 86ad98c
|
It is logically questionable but every C++ resource I know about refers to constants defined with |
clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
Outdated
Show resolved
Hide resolved
3a2ce43
to
e2b34ec
Compare
clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
Outdated
Show resolved
Hide resolved
I'm +1 on |
201b190
to
91acbd6
Compare
This is ebbing into offtopic discussion but "variable" strongly implies it has the ability to be mutated (to vary) at runtime. The same can be said for constants defined via. |
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