https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119798
Bug ID: 119798
Summary: Preprocessor skipping since C17 and C++17
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: preprocessor
Assignee: unassigned at gcc dot gnu.org
Reporter: neilb at protonmail dot ch
Target Milestone: ---
Consider
#if 1
#else foo
#endif
GCC diagnoses the #else with an error with pedantic-errors.
#if 1
#elif
#endif
However GCC accepts without complaint the #elif above even with
pedantic-errors.
This is clearly illogical, and I believe it was corrected by C17 and C++17
standards so both are conforming when noticed by the commmittees. The updated
wording is "Only the first group whose control condition evaluates to true
(nonzero) is processed; any following groups are skipped and their controlling
directives are processed as if they were in a group that is skipped." The
wording after the semicolon was new, the pertinent point being the part about
the controlling directive. I understand this was viewed as a defect in earlier
standards rather than a new "feature", so if GCC developers view this as worth
fixing I suggest it be unconditional and not dependent on language standard
version.
Note both are ill-formed when replacing "#if 1" with "#if 0".