public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Cc: Gabriel Dos Reis <gdr@cs.tamu.edu>
Subject: C++ PATCH to improve 'aka's on type printing in diagnostics
Date: Fri, 01 Jul 2011 18:07:00 -0000	[thread overview]
Message-ID: <4E0DF674.7000307@redhat.com> (raw)
In-Reply-To: <4DF79CA1.7010001@redhat.com>

[-- 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;

  parent reply	other threads:[~2011-07-01 18:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2011-07-04 19:54   ` C++ PATCH to improve 'aka's on type printing in diagnostics Gabriel Dos Reis
2011-07-04 21:29     ` Jason Merrill
2011-07-04 21:31       ` Gabriel Dos Reis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E0DF674.7000307@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gdr@cs.tamu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).