https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121508

--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jakub Jelinek
<[email protected]>:

https://gcc.gnu.org/g:b8c8ee7caec2c828190472ffec272b4f51f35393

commit r14-12935-gb8c8ee7caec2c828190472ffec272b4f51f35393
Author: Jakub Jelinek <[email protected]>
Date:   Mon Sep 21 12:41:35 2026 -0600

    libcpp: Fix up parsing __has_include outside directive [PR121508]

    The r17-4537 change broke several tests especially by introducing
    non-determinism into the preprocessor.  The builtin_has_include_1
    function is expected to set *paren and *bracket flags, and early
    exit from the function without setting those flags means the callers
    then use uninitialized variables.  Also, the early exit means that
    when (incorrectly, sure) one uses __has_include/__has_include_next
    or __has_embed outside of a preprocessing directive but with
    correct syntax, it is diagnosed as both using it outside of
    a preprocessing directive (correct) but also as a random sequence
    of unexpected tokens.  This patch reverts that change.

    I'm guilty of introducing _cpp_get_token_no_padding 6 years ago
    instead of fixing up get_token_no_padding back then, I wasn't
    sure if the eating of CPP_EOF wasn't intentional in some cases,
    but clearly it is never intentional and always a bug.
    After all, get__Pragma_string has been fighting with it already
    by using
      paren = get_token_no_padding (pfile);
      if (paren->type == CPP_EOF)
        _cpp_backup_tokens (pfile, 1);
    glue_header_name and parse_include weren't doing this, but in
    the usual case when pfile->state.in_directive and not lexing a raw string,
    get_fresh_line_impl returns false and _cpp_lex_direct will just keep
    returning CPP_EOF at the end of the line many times until we clear
    the pfile->state.in_directive flag.
    So, I think we should just drop the dangerous get_token_no_padding
    function and simply never eat a CPP_EOF.

    2026-10-09  Jakub Jelinek  <[email protected]>

            PR preprocessor/121508
            PR preprocessor/123339
            * directives.cc (get_token_no_padding): Remove.
            (glue_header_name): Use _cpp_get_token_no_padding instead of
            get_token_no_padding.
            (parse_include): Likewise.
            (get__Pragma_string): Likewise.  Don't _cpp_backup_tokens on
            CPP_EOF.

            * c-c++-common/cpp/pr121508-1.c: New test.
            * c-c++-common/cpp/pr121508-2.c: New test.
            * c-c++-common/cpp/pr121508-3.c: New test.
            * c-c++-common/cpp/pr121508-4.c: New test.
            * c-c++-common/cpp/pr121508-5.c: New test.
            * c-c++-common/cpp/pr123339.c: New test.

    Reviewed-by: Andrea Pinski <[email protected]>
    (cherry picked from commit 9e5fda8ec5716b6fa2b57bdfd56e2b91116a93ff)

Reply via email to