GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libcpp

Fix parsing of __has_include outside directives

Correctly parses __has_include when used outside of preprocessor directives.

This commit reverts a change that caused incorrect parsing of the __has_include preprocessor directive when used outside of its intended context. The previous modification introduced non-determinism and incorrect error handling, leading to uninitialized variables and confusing diagnostic messages. The fix ensures that __has_include and similar built-ins are handled robustly, even when misused, and also removes a problematic function that consumed CPP_EOF tokens.

In Details

A recent change (r17-4537) to builtin_has_include_1 caused it to exit early without setting *paren and *bracket flags, leading to uninitialized variable use in callers. When __has_include was incorrectly used outside a directive, this early exit also caused it to be diagnosed as a random token sequence. This patch reverts that change, re-enables the setting of those flags, and removes the get_token_no_padding function, which incorrectly consumed CPP_EOF tokens, resolving issues in glue_header_name, parse_include, and get__Pragma_string.

For Context
__has_include
A C++20 preprocessor standard feature that checks if a header file can be included. It's typically used within #if or #elif directives.
preprocessor directive
Instructions for the C preprocessor, such as #include, #define, and #if, which are processed before the main compilation stage.
CPP_EOF
The preprocessor token representing the end of the input file.
libcpp
The C++ preprocessor component of GCC.
Filed Under: preprocessorcompilerbugfix