| 1 |
.. title:: clang-tidy - bugprone-reserved-identifier |
| 2 |
|
| 3 |
bugprone-reserved-identifier |
| 4 |
============================ |
| 5 |
|
| 6 |
`cert-dcl37-c` and `cert-dcl51-cpp` redirect here as an alias for this check. |
| 7 |
|
| 8 |
Checks for usages of identifiers reserved for use by the implementation. |
| 9 |
|
| 10 |
The C and C++ standards both reserve the following names for such use: |
| 11 |
|
| 12 |
- identifiers that begin with an underscore followed by an uppercase letter; |
| 13 |
- identifiers in the global namespace that begin with an underscore. |
| 14 |
|
| 15 |
The C standard additionally reserves names beginning with a double underscore, |
| 16 |
while the C++ standard strengthens this to reserve names with a double |
| 17 |
underscore occurring anywhere. |
| 18 |
|
| 19 |
Violating the naming rules above results in undefined behavior. |
| 20 |
|
| 21 |
.. code-block:: c++ |
| 22 |
|
| 23 |
namespace NS { |
| 24 |
void __f(); // name is not allowed in user code |
| 25 |
using _Int = int; // same with this |
| 26 |
#define cool__macro // also this |
| 27 |
} |
| 28 |
int _g(); // disallowed in global namespace only |
| 29 |
|
| 30 |
The check can also be inverted, i.e. it can be configured to flag any |
| 31 |
identifier that is _not_ a reserved identifier. This mode is for use by e.g. |
| 32 |
standard library implementors, to ensure they don't infringe on the user |
| 33 |
namespace. |
| 34 |
|
| 35 |
This check does not (yet) check for other reserved names, e.g. macro names |
| 36 |
identical to language keywords, and names specifically reserved by language |
| 37 |
standards, e.g. C++ 'zombie names' and C future library directions. |
| 38 |
|
| 39 |
This check corresponds to CERT C Coding Standard rule `DCL37-C. Do not declare |
| 40 |
or define a reserved identifier |
| 41 |
<https://wiki.sei.cmu.edu/confluence/display/c/DCL37-C.+Do+not+declare+or+define+a+reserved+identifier>`_ |
| 42 |
as well as its C++ counterpart, `DCL51-CPP. Do not declare or define a reserved |
| 43 |
identifier |
| 44 |
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL51-CPP.+Do+not+declare+or+define+a+reserved+identifier>`_. |
| 45 |
|
| 46 |
Options |
| 47 |
------- |
| 48 |
|
| 49 |
.. option:: Invert |
| 50 |
|
| 51 |
If `true`, inverts the check, i.e. flags names that are not reserved. |
| 52 |
Default is `false`. |
| 53 |
|
| 54 |
.. option:: AllowedIdentifiers |
| 55 |
|
| 56 |
Semicolon-separated list of regular expressions that the check ignores. Default is an |
| 57 |
empty list. |