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.
	* g++.dg/cpp0x/override5.C: New test.

(cherry picked from commit bcb51fe0e26bed7e2c44c4822ca6dec135ba61f3)
3 files changed