public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH to improve dump_decl (PR c++/71075)
@ 2016-05-19 16:45 Marek Polacek
  2016-05-19 16:55 ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Marek Polacek @ 2016-05-19 16:45 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

This PR compains about ugly diagnostics where we print
template argument '2' does not match '#'integer_cst' not supported by dump_decl#<declaration error>'
The following patch teaches dump_decl how to print constants properly.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-05-19  Marek Polacek  <polacek@redhat.com>

	PR c++/71075
	* error.c (dump_decl): Handle *_CST.

	* g++.dg/diagnostic/pr71075.C: New test.

diff --git gcc/cp/error.c gcc/cp/error.c
index 7d70f89..d3232bd 100644
--- gcc/cp/error.c
+++ gcc/cp/error.c
@@ -1269,6 +1269,14 @@ dump_decl (cxx_pretty_printer *pp, tree t, int flags)
       dump_type (pp, t, flags);
       break;
 
+    case VOID_CST:
+    case INTEGER_CST:
+    case REAL_CST:
+    case STRING_CST:
+    case COMPLEX_CST:
+      pp->constant (t);
+      break;
+
     default:
       pp_unsupported_tree (pp, t);
       /* Fall through to error.  */
diff --git gcc/testsuite/g++.dg/diagnostic/pr71075.C gcc/testsuite/g++.dg/diagnostic/pr71075.C
index e69de29..6bb1e68 100644
--- gcc/testsuite/g++.dg/diagnostic/pr71075.C
+++ gcc/testsuite/g++.dg/diagnostic/pr71075.C
@@ -0,0 +1,8 @@
+// PR c++/71075
+
+template<typename T, int I> struct A {};
+template<typename T> void foo(A<T,1>) {}
+int main() {
+  foo(A<int,2>()); // { dg-error "no matching" }
+// { dg-message "template argument .2. does not match .1." "" { target *-*-* } 6 }
+}

	Marek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ PATCH to improve dump_decl (PR c++/71075)
  2016-05-19 16:45 C++ PATCH to improve dump_decl (PR c++/71075) Marek Polacek
@ 2016-05-19 16:55 ` Jason Merrill
  2016-05-19 17:55   ` Marek Polacek
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2016-05-19 16:55 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

Well, constants aren't declarations.  Why are we calling dump_decl here?

Jason

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ PATCH to improve dump_decl (PR c++/71075)
  2016-05-19 16:55 ` Jason Merrill
@ 2016-05-19 17:55   ` Marek Polacek
  2016-05-19 20:03     ` Marek Polacek
  0 siblings, 1 reply; 5+ messages in thread
From: Marek Polacek @ 2016-05-19 17:55 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

On Thu, May 19, 2016 at 12:55:18PM -0400, Jason Merrill wrote:
> Well, constants aren't declarations.  Why are we calling dump_decl here?

Eh, not sure what I was thinking...

We call dump_decl because unify_template_argument_mismatch has %qD:
    inform (input_location,
            "  template argument %qE does not match %qD", arg, parm);
so I suspect we want to print expression ever for PARM:

Untested, but I think it should test fine.  Ok if testing passes?

2016-05-19  Marek Polacek  <polacek@redhat.com>

	PR c++/71075
	* pt.c (unify_template_argument_mismatch): Use %qE instead of %qD.

	* g++.dg/diagnostic/pr71075.C: New test.

diff --git gcc/cp/pt.c gcc/cp/pt.c
index fde3091..ea7778d 100644
--- gcc/cp/pt.c
+++ gcc/cp/pt.c
@@ -6165,7 +6165,7 @@ unify_template_argument_mismatch (bool explain_p, tree parm, tree arg)
 {
   if (explain_p)
     inform (input_location,
-	    "  template argument %qE does not match %qD", arg, parm);
+	    "  template argument %qE does not match %qE", arg, parm);
   return 1;
 }
 
diff --git gcc/testsuite/g++.dg/diagnostic/pr71075.C gcc/testsuite/g++.dg/diagnostic/pr71075.C
index e69de29..6bb1e68 100644
--- gcc/testsuite/g++.dg/diagnostic/pr71075.C
+++ gcc/testsuite/g++.dg/diagnostic/pr71075.C
@@ -0,0 +1,8 @@
+// PR c++/71075
+
+template<typename T, int I> struct A {};
+template<typename T> void foo(A<T,1>) {}
+int main() {
+  foo(A<int,2>()); // { dg-error "no matching" }
+// { dg-message "template argument .2. does not match .1." "" { target *-*-* } 6 }
+}

	Marek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ PATCH to improve dump_decl (PR c++/71075)
  2016-05-19 17:55   ` Marek Polacek
@ 2016-05-19 20:03     ` Marek Polacek
  2016-05-19 20:53       ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Marek Polacek @ 2016-05-19 20:03 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

On Thu, May 19, 2016 at 07:55:05PM +0200, Marek Polacek wrote:
> On Thu, May 19, 2016 at 12:55:18PM -0400, Jason Merrill wrote:
> > Well, constants aren't declarations.  Why are we calling dump_decl here?
> 
> Eh, not sure what I was thinking...
> 
> We call dump_decl because unify_template_argument_mismatch has %qD:
>     inform (input_location,
>             "  template argument %qE does not match %qD", arg, parm);
> so I suspect we want to print expression ever for PARM:
> 
> Untested, but I think it should test fine.  Ok if testing passes?

Which it did.

	Marek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ PATCH to improve dump_decl (PR c++/71075)
  2016-05-19 20:03     ` Marek Polacek
@ 2016-05-19 20:53       ` Jason Merrill
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Merrill @ 2016-05-19 20:53 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

OK.

On Thu, May 19, 2016 at 4:03 PM, Marek Polacek <polacek@redhat.com> wrote:
> On Thu, May 19, 2016 at 07:55:05PM +0200, Marek Polacek wrote:
>> On Thu, May 19, 2016 at 12:55:18PM -0400, Jason Merrill wrote:
>> > Well, constants aren't declarations.  Why are we calling dump_decl here?
>>
>> Eh, not sure what I was thinking...
>>
>> We call dump_decl because unify_template_argument_mismatch has %qD:
>>     inform (input_location,
>>             "  template argument %qE does not match %qD", arg, parm);
>> so I suspect we want to print expression ever for PARM:
>>
>> Untested, but I think it should test fine.  Ok if testing passes?
>
> Which it did.
>
>         Marek

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-05-19 20:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-19 16:45 C++ PATCH to improve dump_decl (PR c++/71075) Marek Polacek
2016-05-19 16:55 ` Jason Merrill
2016-05-19 17:55   ` Marek Polacek
2016-05-19 20:03     ` Marek Polacek
2016-05-19 20:53       ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).