diff mbox

[C++] PR 62315 ("do not print typename in diagnostic if the original code does not have it")

Message ID 689cbd6e-7974-4aa9-9361-9f04f920d9a8@oracle.com
State New
Headers show

Commit Message

Paolo Carlini June 2, 2017, 8:35 a.m. UTC
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.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-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/62315
	* g++.dg/parse/typedef2.C: Specify a dg-error string.

Comments

Paolo Carlini June 23, 2017, 9:53 a.m. UTC | #1
Hi,

gently pingning this:

On 02/06/2017 10:35, Paolo Carlini wrote:
> 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.

     https://gcc.gnu.org/ml/gcc-patches/2017-06/msg00099.html

Thanks!
Paolo.
Jason Merrill June 23, 2017, 8:40 p.m. UTC | #2
OK.

On Fri, Jun 2, 2017 at 4:35 AM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> 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.
>
> //////////////////
>
>
diff mbox

Patch

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))