-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
[clang-tidy] readability-identifier-naming: add support for concepts #71586
Conversation
|
@llvm/pr-subscribers-clang-tidy Author: None (nvartolomei) ChangesFull diff: https://github.com/llvm/llvm-project/pull/71586.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 7539b3899682e13..066057fa7208d55 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -124,6 +124,7 @@ namespace readability {
m(TypeAlias) \
m(MacroDefinition) \
m(ObjcIvar) \
+ m(Concept) \
enum StyleKind : int {
#define ENUMERATE(v) SK_ ## v,
@@ -1391,6 +1392,9 @@ StyleKind IdentifierNamingCheck::findStyleKind(
return SK_Invalid;
}
+ if (isa<ConceptDecl>(D) && NamingStyles[SK_Concept])
+ return SK_Concept;
+
return SK_Invalid;
}
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
index 608bc2acdc0d5e5..e36bbee394f17ae 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
@@ -46,6 +46,7 @@ The following options are described below:
- :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, :option:`ClassConstantSuffix`, :option:`ClassConstantIgnoredRegexp`, :option:`ClassConstantHungarianPrefix`
- :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, :option:`ClassMemberSuffix`, :option:`ClassMemberIgnoredRegexp`, :option:`ClassMemberHungarianPrefix`
- :option:`ClassMethodCase`, :option:`ClassMethodPrefix`, :option:`ClassMethodSuffix`, :option:`ClassMethodIgnoredRegexp`
+ - :option:`ConceptCase`, :option:`ConceptPrefix`, :option:`ConceptSuffix`, :option:`ConceptIgnoredRegexp`
- :option:`ConstantCase`, :option:`ConstantPrefix`, :option:`ConstantSuffix`, :option:`ConstantIgnoredRegexp`, :option:`ConstantHungarianPrefix`
- :option:`ConstantMemberCase`, :option:`ConstantMemberPrefix`, :option:`ConstantMemberSuffix`, :option:`ConstantMemberIgnoredRegexp`, :option:`ConstantMemberHungarianPrefix`
- :option:`ConstantParameterCase`, :option:`ConstantParameterPrefix`, :option:`ConstantParameterSuffix`, :option:`ConstantParameterIgnoredRegexp`, :option:`ConstantParameterHungarianPrefix`
@@ -410,6 +411,46 @@ After:
int pre_class_member_post();
};
+.. option:: ConceptCase
+
+ When defined, the check will ensure concept names conform to the
+ selected casing.
+
+.. option:: ConceptPrefix
+
+ When defined, the check will ensure concept names will add the
+ prefixed with the given value (regardless of casing).
+
+.. option:: ConceptIgnoredRegexp
+
+ Identifier naming checks won't be enforced for concept names
+ matching this regular expression.
+
+.. option:: ConceptSuffix
+
+ When defined, the check will ensure concept names will add the
+ suffix with the given value (regardless of casing).
+
+For example using values of:
+
+ - ConceptCase of ``CamelCase``
+ - ConceptPrefix of ``Pre``
+ - ConceptSuffix of ``Post``
+
+Identifies and/or transforms concept names as follows:
+
+Before:
+
+.. code-block:: c++
+
+ template<typename T> concept my_concept = requires (T t) { {t++}; };
+
+After:
+
+.. code-block:: c++
+
+ template<typename T> concept PreMyConceptPost = requires (T t) { {t++}; };
+
.. option:: ConstantCase
When defined, the check will ensure constant names conform to the
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
index 84bf7764583e801..e375aa098972bfe 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -11,6 +11,7 @@
// RUN: readability-identifier-naming.ClassConstantPrefix: 'k', \
// RUN: readability-identifier-naming.ClassMemberCase: CamelCase, \
// RUN: readability-identifier-naming.ClassMethodCase: camelBack, \
+// RUN: readability-identifier-naming.ConceptCase: CamelCase, \
// RUN: readability-identifier-naming.ConstantCase: UPPER_CASE, \
// RUN: readability-identifier-naming.ConstantSuffix: '_CST', \
// RUN: readability-identifier-naming.ConstexprFunctionCase: lower_case, \
@@ -251,6 +252,15 @@ class my_derived_class : public virtual my_class {};
class CMyWellNamedClass {};
// No warning expected as this class is well named.
+template<typename t_t>
+concept MyConcept = requires (t_t a_t) { {a_t++}; };
+// No warning expected as this concept is well named.
+
+template<typename t_t>
+concept my_concept_2 = requires (t_t a_t) { {a_t++}; };
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for concept 'my_concept_2'
+// CHECK-FIXES: {{^}}concept MyConcept2 = requires (t_t a_t) { {a_t++}; };{{$}}
+
template <typename t_t>
class CMyWellNamedClass2 : public my_class {
// CHECK-FIXES: {{^}}class CMyWellNamedClass2 : public CMyClass {{{$}}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update release notes, and update pull request description.
Except those two, looks fine for me.
Added support for C++20 ``concept`` declarations.
e19e3d3 to
0dbdbc3
Compare
|
@PiotrZSL thank you for your time reviewing this change. I have updated the release notes and PR description. I'm new to this project and not familiar with its customs. Apologize for any mistakes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…lvm#71586) Added support for C++20 ``concept`` declarations.
Added support for C++20
conceptdeclarations.