Hi,
a while ago Manuel noticed that printing 'typename' in error messages
about missing 'typename' can be confusing. That seems easy to fix, in
fact we already handle correctly a similar situation in grokdeclarator.
Tested x86_64-linux.
Thanks, Paolo.
//////////////////
/cp
2017-06-02 Paolo Carlini <paolo.carl...@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-02 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/62315
* g++.dg/parse/typedef2.C: Specify a dg-error string.
Index: testsuite/g++.dg/parse/typedef2.C
===================================================================
--- testsuite/g++.dg/parse/typedef2.C (revision 248783)
+++ testsuite/g++.dg/parse/typedef2.C (working copy)
@@ -1,3 +1,2 @@
template <typename T> struct B { typedef typename T::X X; };
-template <typename T> struct A { typedef B<T>::X::Y Z; }; // { dg-error "" }
-
+template <typename T> struct A { typedef B<T>::X::Y Z; }; // { dg-error
"before 'B<T>::X::Y' because 'B<T>::X'" }
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 248783)
+++ cp/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))