clang-tidy中readability-identifier-naming规则IgnoredRegexp正则表达式使用正确性咨询
The core issue here is that your regex pattern uses invalid syntax for the ECMAScript-style regular expressions clang-tidy relies on. The * quantifier in regex requires a preceding element to apply to—writing *_type doesn’t mean "any characters followed by _type"; instead, it’s a syntax error because there’s nothing before the * to quantify.
Correcting the Regex
To match identifiers ending with _type, exactly equal to reference, or ending with iterator, you need to adjust your regex to follow valid syntax rules:
- Use
.*to match zero or more of any character (the "anything" part you were trying to express) - Add
$to anchor matches at the end of the identifier, ensuring you only catch suffixes (not partial matches in the middle of a name) - Use
^and$together for exact matches likereference
Here’s the corrected pattern:
^reference$|.*(_type|iterator)$
Breaking this down:
^reference$: Matches identifiers that are exactlyreference(no extra characters before or after).*(_type|iterator)$: Matches any identifier ending with_typeoriterator
Updated .clang-tidy Configuration
Replace your existing ignored regex lines with the corrected pattern:
Checks: 'readability-*' CheckOptions: - key: readability-identifier-naming.TypeAliasCase value: CamelCase - key: readability-identifier-naming.TypeAliasIgnoredRegexp value: '^reference$|.*(_type|iterator)$' - key: readability-identifier-naming.TypedefCase value: CamelCase - key: readability-identifier-naming.TypedefIgnoredRegexp value: '^reference$|.*(_type|iterator)$'
Testing the Fix
With this configuration, your example definitions will no longer trigger warnings:
using value_type = T;: Matches.*_type$→ ignoredusing reference = value_type&;: Matches^reference$→ ignoredusing const_iterator = const T*;: Matches.*iterator$→ ignored
If you also want to ignore identifiers ending with reference (not just the exact word), adjust the regex to .*(_type|reference|iterator)$ instead.
内容的提问来源于stack exchange,提问作者PHD

