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

Remediation

Correct the directive name to the intended one. If the line is a note rather than a directive, make it a comment; if it is deliberately unrecognized, keep it inside an #if 0 block so no toolchain has to interpret it.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved