Macro replacement list contains a line that looks like a directive
ID |
objectivec.correctness.macro_body_looks_like_directive |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
medium |
Resource |
Preprocessor |
Language |
Objective-C |
Description
Reports a define whose replacement list continues across a backslash-newline onto a line whose first token is followed by a directive name - include, #if, #pragma and so on. The stringify and ## paste operators are not reported.
Rationale
A replacement list is a sequence of preprocessing tokens, not lines, so the on the continuation line is never processed as a directive. Depending on where the macro is expanded, the toolchain either reports an error far from this definition or silently treats the as a stringify operator applied to the token that follows, so the code the author expected to be conditionally compiled is simply never there. The layout makes it read as though the directive runs, which is why the mistake survives review.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Macro replacement list contains a line that looks like a directive
#define XY_SETUP_LOGGING \
#include "XYLog.h"