2012-06-16 Ville Voutilainen <[email protected]>
Parse virt-specifiers after late-specified return types.
* parser.c (cp_parser_direct_declarator): Move virt-specifier parsing
after late-specified return type parsing
* override4.C: new
Git is doing weird things with my test, its diff shows
a stale file version. Attached here inline:
--snip--
// { dg-do compile }
// { dg-options "--std=c++11" }
struct B
{
virtual auto f() -> void final;
virtual auto g() -> void;
};
struct B2
{
virtual auto f() -> void final {}
};
struct B3
{
virtual auto f() -> final void; // { dg-error "expected type-specifier
before 'final'||expected ';'||declaration doesn't declare anything" }
};
struct B4
{
virtual auto f() -> final void {} // { dg-error "expected
type-specifier before 'final'||expected ';'||declaration doesn't declare
anything" }
};
struct D : B
{
virtual auto g() -> void override;
};
struct D2 : B
{
virtual auto g() -> void override {}
};
struct D3 : B
{
virtual auto g() -> override void; // { dg-error "expected
type-specifier before 'override'||expected ';'||declaration doesn't declare
anything" }
};
struct D4 : B
{
virtual auto g() -> override void {} // { dg-error "expected
type-specifier before 'override'||expected ';'||declaration doesn't declare
anything" }
};
int main()
{
}
--snap--
And the patch:
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 1691f81..6bc6877 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -16102,12 +16102,13 @@ cp_parser_direct_declarator (cp_parser* parser,
/* And the exception-specification. */
exception_specification
= cp_parser_exception_specification_opt (parser);
- /* Parse the virt-specifier-seq. */
- virt_specifiers = cp_parser_virt_specifier_seq_opt (parser);
late_return = (cp_parser_late_return_type_opt
(parser, member_p ? cv_quals : -1));
+ /* Parse the virt-specifier-seq. */
+ virt_specifiers = cp_parser_virt_specifier_seq_opt (parser);
+
/* Create the function-declarator. */
declarator = make_call_declarator (declarator,
params,