Why is this an issue?
This is a draft version of a MISRA C++ 202x rule proposed for public review.
MISRA Rule 19.3.1
Category: Advisory
Analysis Type: Decidable,Single Translation Unit
Rationale
The order of evaluation associated with multiple #
, multiple ##
or a mix of #
and ##
preprocessor operators is unspecified. It is therefore not always possible to predict the result of macro expansion.
The use of the ##
operator can result in code that is hard to understand.
Note: MISRA C++ 2023 Rule 4.1.3 (There shall be no occurrence of undefined or critical unspecified
behaviour) covers the undefined behaviour that arises if either:
- The result of a
#
operator is not a valid string literal; or
- The result of a
##
operator is not a valid preprocessing token.
Copyright The MISRA Consortium Limited © 2023
Resources
Related rules
- S968 targets the same defect as this rule but for a non-mission-critical context.
- MISRA C++ 2023 Rule 4.1.3 - There shall be no occurrence of undefined or critical unspecified behaviour
- MISRA C++ 2023 Rule 19.3.2 - A macro parameter immediately following a
#
operator shall not be immediately followed by a
##
operator
- MISRA C++ 2023 Rule 19.3.3 - The argument to a mixed-use macro parameter shall not be subject to further expansion