Patchwork [/,RFC] PR 50828

login
register
mail settings
Submitter Paolo Carlini
Date Sept. 24, 2012, 2:34 p.m.
Message ID <50606F89.8090604@oracle.com>
Download mbox | patch
Permalink /patch/186442/
State New
Headers show

Comments

Paolo Carlini - Sept. 24, 2012, 2:34 p.m.
Hi,

some time ago Jon filed this diagnostic enhancement PR: explaining it 
requires a bit, please be patient, if you can ;)

Essentially, we are comparing a "note" emitted for

template<typename T>
   struct A {
     template<typename U>
       void f() { }
   };

int main() {
   A<void> a;
   a.f(0);
}

vs the version of the "note" when f isn't a template:

template<typename T>
   struct A {
     void f() { }
   };

int main() {
   A<void> a;
   a.f(0);
}

In the latter case we have:

50828_2.C:3:10: note: void A<T>::f() [with T = void]

whereas in the former we have:

50828_1.C:4:12: note: template<class U> void A::f() [with U = U; T = void]

Note: no <T> after A. This seems an inconsistency (and the T mentioned 
by the text between square brackets becomes quite mysterious).

Now, the issue appears to boil down to the way we are calling 
dump_function_decl: in the non-template case we call it from dump_decl 
simply as:

dump_function_decl (t, flags);

whereas in the template case we call it from dump_template_decl as:

dump_function_decl (t, flags | TFF_TEMPLATE_NAME);

then the TFF_TEMPLATE_NAME is propagated until the final 
dump_template_parms which returns immediately when sees it and doesn't 
print the '<T>'. Calling dump_function_decl in the same way in both 
cases, per the attached patchlet, certainly avoids the inconsistency in 
this specific case (and passes the testsuite FWIW) but I'm not sure it's 
always correct. What do you think? Any tests I could compile by hand to 
check that we aren't breaking anything?

Thanks!
Paolo.

////////////////////////
Jason Merrill - Sept. 24, 2012, 2:53 p.m.
I think dump_function_decl should strip TFF_TEMPLATE_NAME from flags 
before passing flags along to other functions, like dump_template_parms 
does.

Jason

Patch

Index: error.c
===================================================================
--- error.c	(revision 191665)
+++ error.c	(working copy)
@@ -1262,7 +1262,7 @@  dump_template_decl (tree t, int flags)
 	{
 	case METHOD_TYPE:
 	case FUNCTION_TYPE:
-	  dump_function_decl (t, flags | TFF_TEMPLATE_NAME);
+	  dump_function_decl (t, flags);
 	  break;
 	default:
 	  /* This case can occur with some invalid code.  */