]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Don't incorrectly reject override after class head name [PR120569]
authorJakub Jelinek <jakub@redhat.com>
Thu, 10 Jul 2025 21:41:56 +0000 (23:41 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 10 Jul 2025 21:41:56 +0000 (23:41 +0200)
commitbcb51fe0e26bed7e2c44c4822ca6dec135ba61f3
tree215147cdce85c4703e003dc540d931e655476ba4
parentbaaee10123db6cf896283175b345d535b225defb
c++: Don't incorrectly reject override after class head name [PR120569]

While the
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2786r13.html#c03-compatibility-changes-for-annex-c-diff.cpp03.dcl.dcl
hunk dropped because
struct C {}; struct C final {};
is actually not valid C++98 (which didn't have list initialization), we
actually also reject
struct D {}; struct D override {};
and that IMHO is valid all the way from C++11 onwards.
Especially in the light of P2786R13 adding new contextual keywords, I think
it is better to use a separate routine for parsing the
class-virt-specifier-seq (in C++11, there was export next to final),
class-virt-specifier (in C++14 to C++23) and
class-property-specifier-seq (in C++26) instead of using the same function
for virt-specifier-seq and class-property-specifier-seq.

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

PR c++/120569
* parser.cc (cp_parser_class_property_specifier_seq_opt): New
function.
(cp_parser_class_head): Use it instead of
cp_parser_property_specifier_seq_opt.  Don't diagnose
VIRT_SPEC_OVERRIDE here.  Formatting fix.

* g++.dg/cpp0x/override2.C: Expect different diagnostics with
override or duplicate final.
* g++.dg/cpp0x/override5.C: New test.
* g++.dg/cpp0x/duplicate1.C: Expect different diagnostics with
duplicate final.
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp0x/duplicate1.C
gcc/testsuite/g++.dg/cpp0x/override2.C
gcc/testsuite/g++.dg/cpp0x/override5.C [new file with mode: 0644]