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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:86cb35983f55d6039b99b82ace30d2730fcb1eb1

commit r11-2385-g86cb35983f55d6039b99b82ace30d2730fcb1eb1
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Jul 28 15:41:30 2020 +0200

    c++: Fix up cp_lexer_safe_previous_token [PR96328]

    The following testcase ICEs, because cp_lexer_safe_previous_token calls
    cp_lexer_previous_token and that ICEs, because all tokens in the lexer
    buffer before the current one (CPP_EOF) have been purged.

    cp_lexer_safe_previous_token is used in the context where it is ok if it
    punts, so the patch changes the function so that it doesn't assert there is
    some previous token, but instead returns NULL like in other cases where it
    punts.

    In addition to this, in the last hunk it does a micro-optimization, don't
    call the potentially expensive function if it will not need the result,
    instead check the least expensive condition first.

    And the middle hunk is a similar change from Mark's version of the patch,
    to use the safe variant in there because it is again just about a hint
    and it is better not to provide the hint than to ICE, though we don't have
a
    testcase that would ICE.

    2020-07-28  Jakub Jelinek  <ja...@redhat.com>
                Mark Wielaard  <m...@klomp.org>

            PR c++/96328
            * parser.c (cp_lexer_safe_previous_token): Don't call
            cp_lexer_previous_token, instead inline it by hand and return NULL
            instead of failing assertion if all previous tokens until the first
            one are purged.
            (cp_parser_error_1): Optimize - only call
cp_lexer_safe_previous_token
            if token->type is CPP_NAME.  Use cp_lexer_safe_previous_token
instead
            of cp_lexer_previous_token for the missing_token_desc != RT_NONE
            case too.

            * g++.dg/diagnostic/pr96328.C: New test.

    Co-Authored-By: Mark Wielaard <m...@klomp.org>

Reply via email to