public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Gabriel Dos Reis <gdr@cs.tamu.edu>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: C++ PATCH to improve 'aka's on type printing in diagnostics
Date: Mon, 04 Jul 2011 21:29:00 -0000	[thread overview]
Message-ID: <4E123094.6000009@redhat.com> (raw)
In-Reply-To: <87mxgtes9c.fsf@gauss.cs.tamu.edu>

[-- 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." }

  reply	other threads:[~2011-07-04 21:29 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 ` 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 [this message]
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=4E123094.6000009@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).