This is a draft version of a MISRA C++ 202x rule proposed for public review.
MISRA Rule 19.3.5
Category: Required
Analysis Type: Decidable,Single Translation Unit
Rationale
A macro argument containing sequences of tokens that would otherwise act as preprocessing directives results in undefined behaviour.
Example
#define M(A) printf ( #A )
int main()
{
M(
#ifdef SW // Non-compliant
"Message 1"
#else // Non-compliant
"Message 2"
#endif // Non-compliant
);
}
The above could print:
#ifdef SW "Message 1" #else "Message 2" #endif
or it could print:
Message 2
or it could exhibit some other behaviour.
Copyright The MISRA Consortium Limited © 2023