]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* error.c (type_to_string): Avoid redundant akas.
authorJason Merrill <jason@redhat.com>
Mon, 4 Jul 2011 21:43:49 +0000 (17:43 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 4 Jul 2011 21:43:49 +0000 (17:43 -0400)
From-SVN: r175833

gcc/cp/ChangeLog
gcc/cp/error.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/aka1.C [new file with mode: 0644]

index 6ffebf1b0fea402e74902e066cbd893796114b1f..692a95b8e3075abaa40e95462e2b4e77f264805d 100644 (file)
@@ -1,3 +1,7 @@
+2011-07-04  Jason Merrill  <jason@redhat.com>
+
+       * error.c (type_to_string): Avoid redundant akas.
+
 2011-07-01  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        PR c++/49605
index 7c90ec45c17858c992b7474aec2f4e721bd09e52..664b918b31f72975d766154d41b16d70d9a7a42a 100644 (file)
@@ -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);
 }
index fc7336a9d4d3fa29c9265a2d19420ae55f29fdb4..51f8de9842125a9b4a7ab311b0f69a1e8a65a8fb 100644 (file)
@@ -1,3 +1,7 @@
+2011-07-04  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/diagnostic/aka1.C: New.
+
 2011-07-04  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/49619
diff --git a/gcc/testsuite/g++.dg/diagnostic/aka1.C b/gcc/testsuite/g++.dg/diagnostic/aka1.C
new file mode 100644 (file)
index 0000000..37f8df9
--- /dev/null
@@ -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." }