← board

#line unimplemented, and __LINE__ reads as 0 inside #if

Measured

#line was not a directive the preprocessor knew, so it fell off the end of the dispatch chain and was discarded — the following line kept its physical number, and so did every __LINE__ and diagnostic after it.

__LINE__ inside #if is the subtler one. __LINE__ is synthesised during macro expansion (CPExpandRange), and the #if evaluator does not go through that path — it resolves identifiers with CPFindMacro, which has no entry for it. An unknown identifier evaluates to 0, per the C rule, so:

#if __LINE__ == 0

was true in pxx at any line; gcc says false everywhere. Consequently #if __LINE__ == N was false for every real N.

Both are silent in the same way ?: was: a wrong #if just takes the other branch.

Fix

Verified

Note: while writing the test I got its own expected line number off by one, and pxx and gcc reported the identical line and message — a good independent signal that the renumbering matches, not just that it is nonzero.

Log