AutosarC++17_10-A17.0.1

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

Required inputs: IR

This rule detects when reserved identifiers or standard library names are defined, redefined, or undefined as macros. Reserved identifiers are names that the C/C++ standard library and compiler use internally. Redefining them causes undefined behavior: macros may override standard library macros, break built-in compiler behavior, or create conflicts.
Bad code (redefining reserved identifier):
#define _MAX 100          // ERROR: reserved (starts with _uppercase)
#define NULL nullptr      // ERROR: redefining standard macro
#define assert(x) (x)     // ERROR: redefining standard function
#define size_t int        // ERROR: redefining standard type
Bad code (using standard library name):
#define printf myprintf   // ERROR: redefining standard function
#define errno 0           // ERROR: redefining standard identifier
#undef malloc             // ERROR: undefining standard function
Good code (using valid identifiers):
#define MAX_BUFFER 100            // OK: no reserved pattern
#define MY_DEBUG_ASSERT(x) (x)    // OK: custom name
#define APP_VERSION "1.0"         // OK: application-specific
#define CONFIG_OPTION 1           // OK: application namespace
Good code (using namespacing):
// When you must communicate with standard library
#define MY_ASSERT assert          // OK: only internal, explicit linkage
#include <cassert>                // Include after to ensure standard takes precedence

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.