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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-15 branch has been updated by Jakub Jelinek
<ja...@gcc.gnu.org>:

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

commit r15-9956-gbd6cc4f0f6676a895a2178ca397fc51364869bb1
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Thu Jul 10 23:47:42 2025 +0200

    c++: Fix up final handling in C++98 [PR120628]

    The following patch is on top of the
    https://gcc.gnu.org/pipermail/gcc-patches/2025-June/686210.html
    patch which stopped treating override as conditional keyword in
    class properties.
    This PR mentions another problem; we emit a bogus warning on code like
    struct C {}; struct C final = {};
    in C++98.  In this case we parse final as conditional keyword in C++
    (including pedwarn) but the caller then immediately aborts the tentative
    parse because it isn't followed by { nor (in some cases) : .
    I think we certainly shouldn't pedwarn on it, but I think we even shouldn't
    warn for it say for -Wc++11-compat, because we don't actually treat the
    identifier as conditional keyword even in C++11 and later.
    The patch only does this if final is the only class property conditional
    keyword, if one uses
    struct S __final final __final = {};
    one gets the warning and duplicate diagnostics and later parsing errors.

    2025-07-10  Jakub Jelinek  <ja...@redhat.com>

            PR c++/120628
            * parser.cc (cp_parser_elaborated_type_specifier): Use
            cp_parser_nth_token_starts_class_definition_p with extra argument 1
            instead of cp_parser_next_token_starts_class_definition_p.
            (cp_parser_class_property_specifier_seq_opt): For final conditional
            keyword in C++98 check if the token after it isn't
            cp_parser_nth_token_starts_class_definition_p nor CPP_NAME and in
            that case break without consuming it nor warning.
            (cp_parser_class_head): Use
            cp_parser_nth_token_starts_class_definition_p with extra argument 1
            instead of cp_parser_next_token_starts_class_definition_p.
            (cp_parser_next_token_starts_class_definition_p): Renamed to ...
            (cp_parser_nth_token_starts_class_definition_p): ... this.  Add N
            argument.  Use cp_lexer_peek_nth_token instead of
cp_lexer_peek_token.

            * g++.dg/cpp0x/final1.C: New test.
            * g++.dg/cpp0x/final2.C: New test.
            * g++.dg/cpp0x/override6.C: New test.

    (cherry picked from commit 8f063b40e5b8f23cb89fee21afaa71deedbdf2aa)

Reply via email to