AutosarC++19_03-A17.0.1

Reserved identifiers, macros and functions in the C++ standard library shall not be defined, redefined or undefined

Required inputs: IR

Rationale

It is generally bad practice to #undef a macro that is defined in the standard library.

It is also bad practice to #define a macro name that is a C++ reserved identifier, or C++ keyword or the name of any macro, object or function in the standard library. For example, there are some specific reserved words and function names that are known to give rise to undefined behavior if they are redefined or undefined, including defined, __LINE__, __FILE__, __DATE__, __TIME__, __STDC__, errno and assert.

Refer to C++ Language Standard for a list of the identifiers that are reserved. Generally, all identifiers that begin with the underscore character are reserved.

Note that this rule applies regardless of which header files, if any, are actually included.

Example
// $Id: A17-0-1.cpp 271389 2017-03-21 14:41:05Z piotr.tanski $
    #undef __TIME__      // Non-compliant
    #define __LINE__ 20 // Non-compliant
See Also
  • MISRA C++ 2008 [7]: Rule 17-0-1 Reserved identifiers, macros and functions in the standard library shall not be defined, redefined or undefined.

Possible Messages

Key

Text

Severity

Disabled

macro_having_reserved_name

Definition of reserved identifier or standard library element

None

False

undef_of_reserved_name

#undef of reserved identifier or standard library element

None

False

Options

additional_reserved_identifiers

additional_reserved_identifiers : set[str] = {'assert', 'defined', 'errno'}

Names listed here are seen as violations as well.
 

allow_identifiers

allow_identifiers : set[bauhaus.analysis.config.GlobPattern] = {'_CRT_*_NO_WARNINGS'}

Name patterns listed here are not seen as violations.
 

allow_reserved_identifier_as_include_guard

allow_reserved_identifier_as_include_guard : bool = False

If true, macros used for include guards are not checked for being a reserved identifier.
 

check_for_keyword

check_for_keyword : bool = True

Whether macro names being keywords should be reported as well.