Bug 62315 - do not print typename in diagnostic if the original code does not have it
Summary: do not print typename in diagnostic if the original code does not have it
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2014-08-30 18:52 UTC by Manuel López-Ibáñez
Modified: 2017-06-24 19:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-06-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel López-Ibáñez 2014-08-30 18:52:37 UTC
/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'.
Comment 1 Paolo Carlini 2017-06-02 00:32:42 UTC
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))
Comment 2 paolo@gcc.gnu.org 2017-06-24 19:31:56 UTC
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
Comment 3 Paolo Carlini 2017-06-24 19:32:56 UTC
Fixed.