From 136357ac8d1da764c452aa4316ebf8ea7e027457 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sun, 17 Mar 2013 23:41:10 -0400 Subject: [PATCH] re PR c++/54359 ([C++0x] decltype in member function's trailing return type when defined outside of class) PR c++/54359 PR c++/56639 * parser.c (cp_parser_direct_declarator): Bail if we see a qualified-id not at namespace scope. From-SVN: r196765 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/parser.c | 15 ++++++++++++--- gcc/testsuite/g++.dg/parse/typename7.C | 2 +- gcc/testsuite/g++.dg/template/arrow2.C | 12 ++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/arrow2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b341e929790..b2796b6ca13 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2013-03-17 Jason Merrill + PR c++/54359 + PR c++/56639 + * parser.c (cp_parser_direct_declarator): Bail if we see a + qualified-id not at namespace scope. + PR c++/17232 PR c++/56642 * typeck2.c (abstract_virtuals_error_sfinae): Revert complete_type diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 0222e90856f..23fe3f302a0 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -16707,9 +16707,18 @@ cp_parser_direct_declarator (cp_parser* parser, handle_declarator:; scope = get_scope_of_declarator (declarator); if (scope) - /* Any names that appear after the declarator-id for a - member are looked up in the containing scope. */ - pushed_scope = push_scope (scope); + { + /* Any names that appear after the declarator-id for a + member are looked up in the containing scope. */ + if (at_function_scope_p ()) + { + /* But declarations with qualified-ids can't appear in a + function. */ + cp_parser_error (parser, "qualified-id in declaration"); + break; + } + pushed_scope = push_scope (scope); + } parser->in_declarator_p = true; if ((ctor_dtor_or_conv_p && *ctor_dtor_or_conv_p) || (declarator && declarator->kind == cdk_id)) diff --git a/gcc/testsuite/g++.dg/parse/typename7.C b/gcc/testsuite/g++.dg/parse/typename7.C index 2d823f8078e..6ec76961013 100644 --- a/gcc/testsuite/g++.dg/parse/typename7.C +++ b/gcc/testsuite/g++.dg/parse/typename7.C @@ -22,7 +22,7 @@ struct B A().bar(t); } // { dg-error "expected|parse error|no matching" } // { dg-message "candidate" "candidate note" { target *-*-* } 22 } void bad(T t) { - B::bar(t); } // { dg-error "invalid|not a template" } + B::bar(t); } // { dg-error "invalid|qualified-id|not a template" } }; void baz() diff --git a/gcc/testsuite/g++.dg/template/arrow2.C b/gcc/testsuite/g++.dg/template/arrow2.C new file mode 100644 index 00000000000..8ec9e01d0de --- /dev/null +++ b/gcc/testsuite/g++.dg/template/arrow2.C @@ -0,0 +1,12 @@ +// PR c++/56639 + +struct A { + int i; + static A* f(); +}; + +struct B { + void g() { + int (A::f()->i); + } +}; -- 2.30.2