Skip to content

Commit 6fdb1bf

Browse files
authored
[clang-tidy] readability-identifier-naming: add support for concepts (#71586)
Added support for C++20 ``concept`` declarations.
1 parent 24839c3 commit 6fdb1bf

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ namespace readability {
124124
m(TypeAlias) \
125125
m(MacroDefinition) \
126126
m(ObjcIvar) \
127+
m(Concept) \
127128

128129
enum StyleKind : int {
129130
#define ENUMERATE(v) SK_ ## v,
@@ -1391,6 +1392,9 @@ StyleKind IdentifierNamingCheck::findStyleKind(
13911392
return SK_Invalid;
13921393
}
13931394

1395+
if (isa<ConceptDecl>(D) && NamingStyles[SK_Concept])
1396+
return SK_Concept;
1397+
13941398
return SK_Invalid;
13951399
}
13961400

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ Changes in existing checks
399399
``Leading_upper_snake_case`` naming convention. The handling of ``typedef``
400400
has been enhanced, particularly within complex types like function pointers
401401
and cases where style checks were omitted when functions started with macros.
402+
Added support for C++20 ``concept`` declarations.
402403

403404
- Improved :doc:`readability-implicit-bool-conversion
404405
<clang-tidy/checks/readability/implicit-bool-conversion>` check to take

clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The following options are described below:
4646
- :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, :option:`ClassConstantSuffix`, :option:`ClassConstantIgnoredRegexp`, :option:`ClassConstantHungarianPrefix`
4747
- :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, :option:`ClassMemberSuffix`, :option:`ClassMemberIgnoredRegexp`, :option:`ClassMemberHungarianPrefix`
4848
- :option:`ClassMethodCase`, :option:`ClassMethodPrefix`, :option:`ClassMethodSuffix`, :option:`ClassMethodIgnoredRegexp`
49+
- :option:`ConceptCase`, :option:`ConceptPrefix`, :option:`ConceptSuffix`, :option:`ConceptIgnoredRegexp`
4950
- :option:`ConstantCase`, :option:`ConstantPrefix`, :option:`ConstantSuffix`, :option:`ConstantIgnoredRegexp`, :option:`ConstantHungarianPrefix`
5051
- :option:`ConstantMemberCase`, :option:`ConstantMemberPrefix`, :option:`ConstantMemberSuffix`, :option:`ConstantMemberIgnoredRegexp`, :option:`ConstantMemberHungarianPrefix`
5152
- :option:`ConstantParameterCase`, :option:`ConstantParameterPrefix`, :option:`ConstantParameterSuffix`, :option:`ConstantParameterIgnoredRegexp`, :option:`ConstantParameterHungarianPrefix`
@@ -410,6 +411,46 @@ After:
410411
int pre_class_member_post();
411412
};
412413

414+
.. option:: ConceptCase
415+
416+
When defined, the check will ensure concept names conform to the
417+
selected casing.
418+
419+
.. option:: ConceptPrefix
420+
421+
When defined, the check will ensure concept names will add the
422+
prefixed with the given value (regardless of casing).
423+
424+
.. option:: ConceptIgnoredRegexp
425+
426+
Identifier naming checks won't be enforced for concept names
427+
matching this regular expression.
428+
429+
.. option:: ConceptSuffix
430+
431+
When defined, the check will ensure concept names will add the
432+
suffix with the given value (regardless of casing).
433+
434+
For example using values of:
435+
436+
- ConceptCase of ``CamelCase``
437+
- ConceptPrefix of ``Pre``
438+
- ConceptSuffix of ``Post``
439+
440+
Identifies and/or transforms concept names as follows:
441+
442+
Before:
443+
444+
.. code-block:: c++
445+
446+
template<typename T> concept my_concept = requires (T t) { {t++}; };
447+
448+
After:
449+
450+
.. code-block:: c++
451+
452+
template<typename T> concept PreMyConceptPost = requires (T t) { {t++}; };
453+
413454
.. option:: ConstantCase
414455

415456
When defined, the check will ensure constant names conform to the

clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// RUN: readability-identifier-naming.ClassConstantPrefix: 'k', \
1212
// RUN: readability-identifier-naming.ClassMemberCase: CamelCase, \
1313
// RUN: readability-identifier-naming.ClassMethodCase: camelBack, \
14+
// RUN: readability-identifier-naming.ConceptCase: CamelCase, \
1415
// RUN: readability-identifier-naming.ConstantCase: UPPER_CASE, \
1516
// RUN: readability-identifier-naming.ConstantSuffix: '_CST', \
1617
// RUN: readability-identifier-naming.ConstexprFunctionCase: lower_case, \
@@ -251,6 +252,15 @@ class my_derived_class : public virtual my_class {};
251252
class CMyWellNamedClass {};
252253
// No warning expected as this class is well named.
253254

255+
template<typename t_t>
256+
concept MyConcept = requires (t_t a_t) { {a_t++}; };
257+
// No warning expected as this concept is well named.
258+
259+
template<typename t_t>
260+
concept my_concept_2 = requires (t_t a_t) { {a_t++}; };
261+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for concept 'my_concept_2'
262+
// CHECK-FIXES: {{^}}concept MyConcept2 = requires (t_t a_t) { {a_t++}; };{{$}}
263+
254264
template <typename t_t>
255265
class CMyWellNamedClass2 : public my_class {
256266
// CHECK-FIXES: {{^}}class CMyWellNamedClass2 : public CMyClass {{{$}}

0 commit comments

Comments
 (0)