The problem here was that although cp_parser_declarator returned cp_error_declarator, we then wrapped it in another declarator, hiding the problem.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 44b23ac745e9f249ff3971fcb4021facbbf8741c Author: Jason Merrill <ja...@redhat.com> Date: Thu Mar 15 00:14:04 2018 -0400 PR c++/84820 - no error for invalid qualified-id. * parser.c (cp_parser_make_indirect_declarator): Don't wrap cp_error_declarator. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 0a82f415196..119f6c078f7 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3823,7 +3823,7 @@ cp_parser_make_indirect_declarator (enum tree_code code, tree class_type, cp_declarator *target, tree attributes) { - if (code == ERROR_MARK) + if (code == ERROR_MARK || target == cp_error_declarator) return cp_error_declarator; if (code == INDIRECT_REF) diff --git a/gcc/testsuite/g++.dg/parse/error21.C b/gcc/testsuite/g++.dg/parse/error21.C index 8c717d7e811..920a4909e15 100644 --- a/gcc/testsuite/g++.dg/parse/error21.C +++ b/gcc/testsuite/g++.dg/parse/error21.C @@ -8,6 +8,5 @@ void foo() // Check that we do not complain about an unused // compiler-generated variable. A& = a; // { dg-error "6:expected unqualified-id before '=' token" "6" } - // { dg-error "8:'a' was not declared in this scope" "8" { target *-*-* } .-1 } } diff --git a/gcc/testsuite/g++.dg/parse/qualified5.C b/gcc/testsuite/g++.dg/parse/qualified5.C new file mode 100644 index 00000000000..dff934e98b1 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/qualified5.C @@ -0,0 +1,13 @@ +// PR c++/84820 + +struct A {}; + +template<int> struct B : A +{ + B() + { + A(&A::foo); // { dg-error "foo" } + } +}; + +B<0> b;