Macro parameter is both stringified and pasted
ID |
objectivec.maintainability.macro_stringify_paste_adjacent |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Preprocessor |
Language |
Objective-C |
Description
Reports a macro replacement list in which a operator and a operator apply to the same parameter, as in #ab. A or a used on its own, and the GNU , VA_ARGS comma-swallowing idiom, are not reported.
Rationale
The standard does not fix the order in which and # are evaluated within one replacement list. Stringify-then-paste and paste-then-stringify produce different text, so the macro can expand to different code on different toolchains, or on different versions of the same one, with no diagnostic anywhere. Because the difference only shows up in the expanded output, it usually surfaces as a puzzling error at an unrelated call site.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Macro parameter is both stringified and pasted
#define XY_STR_CAT(a, b) #a##b