Declared name is a keyword in C++ or a later C standard
ID |
c.maintainability.naming_keyword_identifier |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Naming |
Language |
C / C++ |
Description
Reports a variable, function, or macro declared with a name that is plain in the current C standard but reserved as a keyword in C++: final, override, module, import, and nullptr.
Rationale
These words are ordinary identifiers today, so the declaration compiles, but each one is reserved for a specific purpose in C. Compiling the same translation unit as C, or mixing this header into a C++ project, turns the declaration into a syntax error at the exact line the name is used, with a compiler message that talks about the keyword rather than about the code.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Declared name is a keyword in C++ or a later C standard
int final;