public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/49117 (error message regression on conversion failure)
@ 2011-06-14 17:46 Jason Merrill
  2011-06-18 14:20 ` Jakub Jelinek
  2011-07-01 18:07 ` C++ PATCH to improve 'aka's on type printing in diagnostics Jason Merrill
  0 siblings, 2 replies; 6+ messages in thread
From: Jason Merrill @ 2011-06-14 17:46 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 411 bytes --]

PR 49117 complains that the error message given on conversion failure 
regressed from 4.5 to 4.6 in that it no longer prints the source type. 
So I've added it back in.

While I was at it, I've also tweaked the compiler to also print the 
typedef-stripped version of a type when appropriate, which should help 
with understanding template error messages.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.

[-- Attachment #2: 49117.patch --]
[-- Type: text/x-patch, Size: 1734 bytes --]

commit 2978b60371c26f46ba5ac44244d94ef100cf9cf2
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 14 09:43:04 2011 -0400

    	PR c++/49117
    	* call.c (perform_implicit_conversion_flags): Print source type as
    	well as expression.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4ee0eaf..b43d078 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8296,7 +8296,8 @@ perform_implicit_conversion_flags (tree type, tree expr, tsubst_flags_t complain
 	  else if (invalid_nonstatic_memfn_p (expr, complain))
 	    /* We gave an error.  */;
 	  else
-	    error ("could not convert %qE to %qT", expr, type);
+	    error ("could not convert %qE from %qT to %qT", expr,
+		   TREE_TYPE (expr), type);
 	}
       expr = error_mark_node;
     }
diff --git a/gcc/testsuite/g++.dg/other/error23.C b/gcc/testsuite/g++.dg/other/error23.C
index 0ff1915..959fe40 100644
--- a/gcc/testsuite/g++.dg/other/error23.C
+++ b/gcc/testsuite/g++.dg/other/error23.C
@@ -2,4 +2,4 @@
 // { dg-do compile }
 
 int v __attribute ((vector_size (8)));
-bool b = !(v - v);	// { dg-error "could not convert .\\(__vector.2. int\\)\\{0, 0\\}. to .bool.|in argument to unary" }
+bool b = !(v - v);	// { dg-error "could not convert .\\(__vector.2. int\\)\\{0, 0\\}. from .__vector.2. int. to .bool.|in argument to unary" }
diff --git a/gcc/testsuite/g++.dg/other/error32.C b/gcc/testsuite/g++.dg/other/error32.C
index 35c64c4..56d3b7a 100644
--- a/gcc/testsuite/g++.dg/other/error32.C
+++ b/gcc/testsuite/g++.dg/other/error32.C
@@ -3,6 +3,6 @@
 
 void foo()
 {
-  if (throw 0) // { dg-error "could not convert .\\<throw-expression\\>. to .bool." }
+  if (throw 0) // { dg-error "could not convert .\\<throw-expression\\>. from .void. to .bool." }
     ;
 }

[-- Attachment #3: aka.patch --]
[-- Type: text/x-patch, Size: 758 bytes --]

commit 16136651e85c19a1e8338a0bd1b2b1a453413c23
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 14 09:43:25 2011 -0400

    	* error.c (type_to_string): Print typedef-stripped version too.

diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 96796c2..22470dc 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2632,6 +2632,15 @@ type_to_string (tree typ, int verbose)
 
   reinit_cxx_pp ();
   dump_type (typ, flags);
+  if (typ && TYPE_P (typ) && typ != TYPE_CANONICAL (typ)
+      && !uses_template_parms (typ))
+    {
+      tree aka = strip_typedefs (typ);
+      pp_string (cxx_pp, " {aka");
+      pp_cxx_whitespace (cxx_pp);
+      dump_type (aka, flags);
+      pp_character (cxx_pp, '}');
+    }
   return pp_formatted_text (cxx_pp);
 }
 

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

* Re: C++ PATCH for c++/49117 (error message regression on conversion failure)
  2011-06-14 17:46 C++ PATCH for c++/49117 (error message regression on conversion failure) Jason Merrill
@ 2011-06-18 14:20 ` Jakub Jelinek
  2011-07-01 18:07 ` C++ PATCH to improve 'aka's on type printing in diagnostics Jason Merrill
  1 sibling, 0 replies; 6+ messages in thread
From: Jakub Jelinek @ 2011-06-18 14:20 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

On Tue, Jun 14, 2011 at 01:38:41PM -0400, Jason Merrill wrote:
> commit 16136651e85c19a1e8338a0bd1b2b1a453413c23
> Author: Jason Merrill <jason@redhat.com>
> Date:   Tue Jun 14 09:43:25 2011 -0400
> 
>     	* error.c (type_to_string): Print typedef-stripped version too.
> 
> diff --git a/gcc/cp/error.c b/gcc/cp/error.c
> index 96796c2..22470dc 100644
> --- a/gcc/cp/error.c
> +++ b/gcc/cp/error.c
> @@ -2632,6 +2632,15 @@ type_to_string (tree typ, int verbose)
>  
>    reinit_cxx_pp ();
>    dump_type (typ, flags);
> +  if (typ && TYPE_P (typ) && typ != TYPE_CANONICAL (typ)
> +      && !uses_template_parms (typ))
> +    {
> +      tree aka = strip_typedefs (typ);
> +      pp_string (cxx_pp, " {aka");
> +      pp_cxx_whitespace (cxx_pp);
> +      dump_type (aka, flags);
> +      pp_character (cxx_pp, '}');
> +    }
>    return pp_formatted_text (cxx_pp);
>  }
>  

This caused
FAIL: obj-c++.dg/invalid-type-1.mm -fgnu-runtime  (test for errors, line 21)
FAIL: obj-c++.dg/invalid-type-1.mm -fgnu-runtime  (test for errors, line 24)
FAIL: obj-c++.dg/invalid-type-1.mm -fgnu-runtime (test for excess errors)
failures, fixed thusly, committed as obvious to trunk and 4.6:

2011-06-18  Jakub Jelinek  <jakub@redhat.com>

	PR testsuite/49432
	* obj-c++.dg/invalid-type-1.mm: Adjust for new error wording.

--- gcc/testsuite/obj-c++.dg/invalid-type-1.mm.jj	2010-11-15 18:53:29.000000000 +0100
+++ gcc/testsuite/obj-c++.dg/invalid-type-1.mm	2011-06-18 14:52:57.873566940 +0200
@@ -18,8 +18,8 @@ id <MyProtocol> object; /* This is fine.
 
 AClass <MyProtocol> *object1; /* This is fine.  */
 
-Integer <MyProtocol> *object2; /* { dg-error ".Integer. is not a template" } */
+Integer <MyProtocol> *object2; /* { dg-error ".Integer {aka int}. is not a template" } */
 /* { dg-error ".MyProtocol. was not declared in this scope" "" { target *-*-* } 21 } */
 
-Integer <NonExistingProtocol> *object3; /* { dg-error ".Integer. is not a template" } */
+Integer <NonExistingProtocol> *object3; /* { dg-error ".Integer {aka int}. is not a template" } */
 /* { dg-error ".NonExistingProtocol. was not declared in this scope" "" { target *-*-* } 24 } */


	Jakub

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

* C++ PATCH to improve 'aka's on type printing in diagnostics
  2011-06-14 17:46 C++ PATCH for c++/49117 (error message regression on conversion failure) Jason Merrill
  2011-06-18 14:20 ` Jakub Jelinek
@ 2011-07-01 18:07 ` Jason Merrill
  2011-07-04 19:54   ` Gabriel Dos Reis
  1 sibling, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-07-01 18:07 UTC (permalink / raw)
  To: gcc-patches List; +Cc: Gabriel Dos Reis

[-- Attachment #1: Type: text/plain, Size: 709 bytes --]

On 06/14/2011 01:38 PM, Jason Merrill wrote:
> While I was at it, I've also tweaked the compiler to also print the
> typedef-stripped version of a type when appropriate, which should help
> with understanding template error messages.

I noticed that this was sometimes printing an aka that was exactly the 
same, which looks a bit goofy.  So this patch makes sure that the 
typedef-stripped version actually prints out differently before 
appending the {aka}.

Tested x86_64-pc-linux-gnu.  Gaby: I'm not entirely comfortable messing 
directly with the obstack here, but the pp interface doesn't seem to 
support multiple strings at once.  Does this approach make sense to you, 
or do you have a better idea?


[-- Attachment #2: aka-2.patch --]
[-- Type: text/x-patch, Size: 1644 bytes --]

commit 27301c5f28e808c3a6ba6e5184a6968ad12fc939
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jul 1 00:16:46 2011 -0400

    	* error.c (cp_printer): Print 'aka' here.
    	(type_to_string): Not here.

diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 7c90ec4..330bf46 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2634,15 +2634,6 @@ type_to_string (tree typ, int verbose)
 
   reinit_cxx_pp ();
   dump_type (typ, flags);
-  if (typ && TYPE_P (typ) && typ != TYPE_CANONICAL (typ)
-      && !uses_template_parms (typ))
-    {
-      tree aka = strip_typedefs (typ);
-      pp_string (cxx_pp, " {aka");
-      pp_cxx_whitespace (cxx_pp);
-      dump_type (aka, flags);
-      pp_character (cxx_pp, '}');
-    }
   return pp_formatted_text (cxx_pp);
 }
 
@@ -3142,6 +3133,26 @@ cp_printer (pretty_printer *pp, text_info *text, const char *spec,
     }
 
   pp_base_string (pp, result);
+
+  /* If we're printing a type that involves typedefs, also print the
+     stripped version.  */
+  if (*spec == 'T' && t && TYPE_P (t) && t != TYPE_CANONICAL (t)
+      && !uses_template_parms (t))
+    {
+      tree aka = strip_typedefs (t);
+      char *old = (char *)obstack_finish (pp_base (cxx_pp)->buffer->obstack);
+      gcc_assert (old == result);
+      result = type_to_string (aka, verbose);
+      gcc_assert (old != result);
+      if (strcmp (result, old) != 0)
+	{
+	  pp_base_string (pp, " {aka ");
+	  pp_base_string (pp, result);
+	  pp_base_character (pp, '}');
+	}
+      obstack_free (pp_base (cxx_pp)->buffer->obstack, old);
+    }
+
   if (set_locus && t != NULL)
     *text->locus = location_of (t);
   return true;

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

* Re: C++ PATCH to improve 'aka's on type printing in diagnostics
  2011-07-01 18:07 ` C++ PATCH to improve 'aka's on type printing in diagnostics Jason Merrill
@ 2011-07-04 19:54   ` Gabriel Dos Reis
  2011-07-04 21:29     ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Gabriel Dos Reis @ 2011-07-04 19:54 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

Jason Merrill <jason@redhat.com> writes:

| On 06/14/2011 01:38 PM, Jason Merrill wrote:
| > While I was at it, I've also tweaked the compiler to also print the
| > typedef-stripped version of a type when appropriate, which should help
| > with understanding template error messages.
| 
| I noticed that this was sometimes printing an aka that was exactly the
| same, which looks a bit goofy.  So this patch makes sure that the
| typedef-stripped version actually prints out differently before
| appending the {aka}.
| 
| Tested x86_64-pc-linux-gnu.  Gaby: I'm not entirely comfortable
| messing directly with the obstack here, but the pp interface doesn't
| seem to support multiple strings at once.  Does this approach make
| sense to you, or do you have a better idea?
| 

Hi Jason,

Please go ahead with your patch, and open a PR request for a better
interface (assigned to me).  The diagnostic machinery should support
what you want to do without people having to deal directly with the
lower-level storage management.  Thanks! 

-- Gaby

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

* Re: C++ PATCH to improve 'aka's on type printing in diagnostics
  2011-07-04 19:54   ` Gabriel Dos Reis
@ 2011-07-04 21:29     ` Jason Merrill
  2011-07-04 21:31       ` Gabriel Dos Reis
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-07-04 21:29 UTC (permalink / raw)
  To: Gabriel Dos Reis; +Cc: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 181 bytes --]

I thought of a different way to do it that would stay encapsulated in 
type_as_string, so this is the version I'm going to check in.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: aka-2.patch --]
[-- Type: text/x-patch, Size: 1984 bytes --]

commit 689a3e58f4eebbcdafec81f06e8af699045fff3a
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jul 1 00:16:46 2011 -0400

    	* error.c (type_to_string): Avoid redundant akas.

diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 7c90ec4..664b918 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2634,14 +2634,28 @@ type_to_string (tree typ, int verbose)
 
   reinit_cxx_pp ();
   dump_type (typ, flags);
+  /* If we're printing a type that involves typedefs, also print the
+     stripped version.  But sometimes the stripped version looks
+     exactly the same, so we don't want it after all.  To avoid printing
+     it in that case, we play ugly obstack games.  */
   if (typ && TYPE_P (typ) && typ != TYPE_CANONICAL (typ)
       && !uses_template_parms (typ))
     {
+      int aka_start; char *p;
+      struct obstack *ob = pp_base (cxx_pp)->buffer->obstack;
+      /* Remember the end of the initial dump.  */
+      int len = obstack_object_size (ob);
       tree aka = strip_typedefs (typ);
       pp_string (cxx_pp, " {aka");
       pp_cxx_whitespace (cxx_pp);
+      /* And remember the start of the aka dump.  */
+      aka_start = obstack_object_size (ob);
       dump_type (aka, flags);
       pp_character (cxx_pp, '}');
+      p = (char*)obstack_base (ob);
+      /* If they are identical, cut off the aka with a NUL.  */
+      if (memcmp (p, p+aka_start, len) == 0)
+	p[len] = '\0';
     }
   return pp_formatted_text (cxx_pp);
 }
diff --git a/gcc/testsuite/g++.dg/diagnostic/aka1.C b/gcc/testsuite/g++.dg/diagnostic/aka1.C
new file mode 100644
index 0000000..37f8df9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/aka1.C
@@ -0,0 +1,15 @@
+// Basic test for typedef stripping in diagnostics.
+
+struct A {
+  void f();
+};
+
+void A::f() {
+  // We don't want an aka for the injected-class-name.
+  A a = 0;			// { dg-error "type .A. requested" }
+}
+
+typedef A B;
+
+// We do want an aka for a real typedef.
+B b = 0;			// { dg-error "B .aka A." }

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

* Re: C++ PATCH to improve 'aka's on type printing in diagnostics
  2011-07-04 21:29     ` Jason Merrill
@ 2011-07-04 21:31       ` Gabriel Dos Reis
  0 siblings, 0 replies; 6+ messages in thread
From: Gabriel Dos Reis @ 2011-07-04 21:31 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

Jason Merrill <jason@redhat.com> writes:

| I thought of a different way to do it that would stay encapsulated in
| type_as_string, so this is the version I'm going to check in.

OK, thanks.

-- Gaby

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

end of thread, other threads:[~2011-07-04 21:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-14 17:46 C++ PATCH for c++/49117 (error message regression on conversion failure) Jason Merrill
2011-06-18 14:20 ` Jakub Jelinek
2011-07-01 18:07 ` C++ PATCH to improve 'aka's on type printing in diagnostics Jason Merrill
2011-07-04 19:54   ` Gabriel Dos Reis
2011-07-04 21:29     ` Jason Merrill
2011-07-04 21:31       ` Gabriel Dos Reis

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