Line begins with # but is not a valid preprocessing directive
ID |
objectivec.correctness.invalid_preprocessing_directive |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Preprocessor |
Language |
Objective-C |
Description
Reports a line whose first token is followed by something that is not one of the directives the preprocessor recognizes. The null directive ( alone), a line-marker (# 42 "file.m") and the # stringify operator on a macro continuation line are not reported.
Rationale
A # in the first token position tells the preprocessor to read a directive, and a name it does not recognize is a constraint violation. Which means a typo - #endfi for #endif, #elseif for #elif - can silently change which branches of a file are compiled on a toolchain that only warns, so the file builds but with the wrong code selected. The mistake is invisible in review because the line reads like the directive it was meant to be.
The following code illustrates the pattern detected by this rule:
#define XY_JOIN(a, b) \
a##b
// FLAGGED: Line begins with # but is not a valid preprocessing directive
#endfi