/home/manuel/test2/src/gcc/testsuite/g++.dg/parse/typedef2.C:2:42: error: need ‘typename’ before ‘typename B<T>::X::Y’ because ‘typename B<T>::X’ is a dependent scope template <typename T> struct A { typedef B<T>::X::Y Z; }; // { dg-error "" } ^ It is confusing to say that typename is needed before 'typename B<T>::X::Y'.
In such cases of TYPENAME_TYPEs, printing separately TYPE_CONTEXT and TYPENAME_TYPE_FULLNAME, like we already do in grokdeclarator, should work: Index: parser.c =================================================================== --- parser.c (revision 248783) +++ parser.c (working copy) @@ -3270,9 +3270,21 @@ cp_parser_diagnose_invalid_type_name (cp_parser *p } else if (TYPE_P (parser->scope) && dependent_scope_p (parser->scope)) - error_at (location, "need %<typename%> before %<%T::%E%> because " - "%qT is a dependent scope", - parser->scope, id, parser->scope); + { + if (TREE_CODE (parser->scope) == TYPENAME_TYPE) + error_at (location, + "need %<typename%> before %<%T::%D::%E%> because " + "%<%T::%D%> is a dependent scope", + TYPE_CONTEXT (parser->scope), + TYPENAME_TYPE_FULLNAME (parser->scope), + id, + TYPE_CONTEXT (parser->scope), + TYPENAME_TYPE_FULLNAME (parser->scope)); + else + error_at (location, "need %<typename%> before %<%T::%E%> because " + "%qT is a dependent scope", + parser->scope, id, parser->scope); + } else if (TYPE_P (parser->scope)) { if (!COMPLETE_TYPE_P (parser->scope))
Author: paolo Date: Sat Jun 24 19:31:24 2017 New Revision: 249626 URL: https://gcc.gnu.org/viewcvs?rev=249626&root=gcc&view=rev Log: /cp 2017-06-24 Paolo Carlini <paolo.carlini@oracle.com> PR c++/62315 * parser.c (cp_parser_diagnose_invalid_type_name): Don't print 'typename' in error messages about missing 'typename'. /testsuite 2017-06-24 Paolo Carlini <paolo.carlini@oracle.com> PR c++/62315 * g++.dg/parse/typedef2.C: Specify a dg-error string. Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/parser.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/parse/typedef2.C
Fixed.