]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
C/C++: fix quoting of "aka" typedef information (PR 62170)
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 22 Nov 2017 20:37:58 +0000 (20:37 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Wed, 22 Nov 2017 20:37:58 +0000 (20:37 +0000)
PR 62170 describes a problem with how the quoting in pp_format
interacts with the "aka" information for typedefs in %qT for
the C family of frontends, and also now for %qH and %qI in the
C++ frontend: we print:

  'Py_ssize_t* {aka int*}'
   ^^^^^^^^^^^^^^^^^^^^^^ colorized as "quote"

i.e.
  '[START_COLOR]Py_ssize_t* {aka int*}[END_COLOR]'

when we should print:

  'Py_ssize_t*' {aka 'int*'}
   ^^^^^^^^^^^        ^^^^ colorized as "quote"

i.e.
  '[START_COLOR]Py_ssize_t*[END_COLOR]' {aka '[START_COLOR]int*[END_COLOR]'}

where the opening and closing quote characters and colorization are
added by the 'q' handling within pp_format.

This patch fixes the quoting by updating the %T handling in C and C++
and the %H/%I handling in C++ to insert the quoting appropriately.
It converts the "quote" param of the pp_format_decoder callback from
bool to bool *, allowing for the %T and %H/%I handlers to write
false back to it, to avoid printing the closing quote for the cases
like the above where the trailing closing quote isn't needed.

It introduces pp_begin_quote/pp_end_quote to simplify this.  These
take a "bool show_color", rather than using "pp_show_color (pp)"
since cxx_pp's pp_show_color isn't currently initialized (since
cxx_initialize_diagnostics happens before diagnostic_color_init).

gcc/c/ChangeLog:
PR c++/62170
* c-objc-common.c (c_tree_printer): Convert penultimate param from
bool to bool *.  Within '%T' handling, if showing an "aka", use
"quoted" param to add appropriate quoting.

gcc/cp/ChangeLog:
PR c++/62170
* error.c (type_to_string): Add leading comment.  Add params
"postprocessed", "quote", and "show_color", using them to fix
quoting of the "aka" for types involving typedefs.
(arg_to_string): Update for new params to type_to_string.
(cxx_format_postprocessor::handle): Likewise.
(cp_printer): Convert penultimate param from bool to bool *.
Update call to type_to_string and calls to
defer_phase_2_of_type_diff.

gcc/fortran/ChangeLog:
PR c++/62170
* error.c (gfc_notify_std): Convert "quoted" param from bool to
bool *.

gcc/ChangeLog:
PR c++/62170
* pretty-print.c (pp_format): Move quoting implementation to
pp_begin_quote and pp_end_quote.  Update pp_format_decoder call
to pass address of "quote" local.
(pp_begin_quote): New function.
(pp_end_quote): New function.
* pretty-print.h (printer_fn): Convert penultimate param from bool
to bool *.
(pp_begin_quote): New decl.
(pp_end_quote): New decl.
* tree-diagnostic.c (default_tree_printer): Convert penultimate
param from bool to bool *.
* tree-diagnostic.h (default_tree_printer): Likewise.

gcc/testsuite/ChangeLog:
PR c++/62170
* g++.dg/diagnostic/aka1.C: Update expected error messages to
reflect fixes to quoting.
* g++.dg/diagnostic/aka2.C: New test case.
* g++.dg/parse/error55.C: Update expected error messages to
reflect fixes to quoting.
* gcc.dg/diag-aka-1.c: Likewise.
* gcc.dg/diag-aka-2.c: New test case.
* gcc.dg/pr13804-1.c: Update expected error messages to reflect
fixes to quoting.
* gcc.dg/pr56980.c: Likewise.
* gcc.dg/pr65050.c: Likewise.
* gcc.dg/redecl-14.c: Likewise.
* gcc.dg/utf16-4.c Likewise.
* gcc.target/i386/sse-vect-types.c (__m128d): Likewise.
* obj-c++.dg/invalid-type-1.mm: Likewise.
* objc.dg/proto-lossage-4.m: Likewise.

From-SVN: r255076

25 files changed:
gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/c-objc-common.c
gcc/cp/ChangeLog
gcc/cp/error.c
gcc/fortran/ChangeLog
gcc/fortran/error.c
gcc/pretty-print.c
gcc/pretty-print.h
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/aka1.C
gcc/testsuite/g++.dg/diagnostic/aka2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/error55.C
gcc/testsuite/gcc.dg/diag-aka-1.c
gcc/testsuite/gcc.dg/diag-aka-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr13804-1.c
gcc/testsuite/gcc.dg/pr56980.c
gcc/testsuite/gcc.dg/pr65050.c
gcc/testsuite/gcc.dg/redecl-14.c
gcc/testsuite/gcc.dg/utf16-4.c
gcc/testsuite/gcc.target/i386/sse-vect-types.c
gcc/testsuite/obj-c++.dg/invalid-type-1.mm
gcc/testsuite/objc.dg/proto-lossage-4.m
gcc/tree-diagnostic.c
gcc/tree-diagnostic.h

index 4ecf5bcc038f3331df620f765eb961b1eb2a1435..c9793ece18d1e595632f3989cd737aa0ceefff39 100644 (file)
@@ -1,3 +1,19 @@
+2017-11-22  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c++/62170
+       * pretty-print.c (pp_format): Move quoting implementation to
+       pp_begin_quote and pp_end_quote.  Update pp_format_decoder call
+       to pass address of "quote" local.
+       (pp_begin_quote): New function.
+       (pp_end_quote): New function.
+       * pretty-print.h (printer_fn): Convert penultimate param from bool
+       to bool *.
+       (pp_begin_quote): New decl.
+       (pp_end_quote): New decl.
+       * tree-diagnostic.c (default_tree_printer): Convert penultimate
+       param from bool to bool *.
+       * tree-diagnostic.h (default_tree_printer): Likewise.
+
 2017-11-22  Jeff Law  <law@redhat.com>
 
        * gimple-ssa-evrp-analyze.c (evrp_range_analyzer::evrp_range_analyzer)
index b936f9920899738c43c3ece20afb52fd0cb1d18e..344eb262a1b8e17e05677f100f459f9caba25254 100644 (file)
@@ -1,3 +1,10 @@
+2017-11-22  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c++/62170
+       * c-objc-common.c (c_tree_printer): Convert penultimate param from
+       bool to bool *.  Within '%T' handling, if showing an "aka", use
+       "quoted" param to add appropriate quoting.
+
 2017-11-22  Marek Polacek  <polacek@redhat.com>
 
        PR c++/60336
index 8f4d3eb91c538538db7f0797fd0b6d7ac6ec8bb4..6d923eb64e753ee6097efcd2e31294935c49abfb 100644 (file)
@@ -29,7 +29,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "c-objc-common.h"
 
 static bool c_tree_printer (pretty_printer *, text_info *, const char *,
-                           int, bool, bool, bool, bool, const char **);
+                           int, bool, bool, bool, bool *, const char **);
 
 bool
 c_missing_noreturn_ok_p (tree decl)
@@ -79,7 +79,7 @@ c_objc_common_init (void)
 static bool
 c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
                int precision, bool wide, bool set_locus, bool hash,
-               bool, const char **)
+               bool *quoted, const char **)
 {
   tree t = NULL_TREE;
   tree name;
@@ -166,12 +166,20 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
              return true;
 
            /* They're not, print the stripped version now.  */
+           if (*quoted)
+             pp_end_quote (pp, pp_show_color (pp));
            pp_c_whitespace (cpp);
            pp_left_brace (cpp);
            pp_c_ws_string (cpp, _("aka"));
            pp_c_whitespace (cpp);
+           if (*quoted)
+             pp_begin_quote (pp, pp_show_color (pp));
            cpp->type_id (TYPE_CANONICAL (t));
+           if (*quoted)
+             pp_end_quote (pp, pp_show_color (pp));
            pp_right_brace (cpp);
+           /* No further closing quotes are needed.  */
+           *quoted = false;
          }
        return true;
       }
index f7d3cfa4d3422ca5212a1334d90d6ea890bb20c6..f97187eaf1cd950d5c42c58b0b7fef8aa0ae032d 100644 (file)
@@ -1,3 +1,15 @@
+2017-11-22  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c++/62170
+       * error.c (type_to_string): Add leading comment.  Add params
+       "postprocessed", "quote", and "show_color", using them to fix
+       quoting of the "aka" for types involving typedefs.
+       (arg_to_string): Update for new params to type_to_string.
+       (cxx_format_postprocessor::handle): Likewise.
+       (cp_printer): Convert penultimate param from bool to bool *.
+       Update call to type_to_string and calls to
+       defer_phase_2_of_type_diff.
+
 2017-11-22  Marek Polacek  <polacek@redhat.com>
 
        PR c++/60336
index 6d1f3da74e2eff5722a2dcd0a9df0d921f427aa7..a47822a2d1bdb8894039f3834cca9e65123e3191 100644 (file)
@@ -57,7 +57,7 @@ static const char *expr_to_string (tree);
 static const char *fndecl_to_string (tree, int);
 static const char *op_to_string        (bool, enum tree_code);
 static const char *parm_to_string (int);
-static const char *type_to_string (tree, int);
+static const char *type_to_string (tree, int, bool, bool *, bool);
 
 static void dump_alias_template_specialization (cxx_pretty_printer *, tree, int);
 static void dump_type (cxx_pretty_printer *, tree, int);
@@ -99,7 +99,7 @@ static void cp_diagnostic_starter (diagnostic_context *, diagnostic_info *);
 static void cp_print_error_function (diagnostic_context *, diagnostic_info *);
 
 static bool cp_printer (pretty_printer *, text_info *, const char *,
-                       int, bool, bool, bool, bool, const char **);
+                       int, bool, bool, bool, bool *, const char **);
 
 /* Struct for handling %H or %I, which require delaying printing the
    type until a postprocessing stage.  */
@@ -3144,8 +3144,28 @@ op_to_string (bool assop, enum tree_code p)
   return id ? IDENTIFIER_POINTER (id) : M_("<unknown>");
 }
 
+/* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
+
+   If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
+   string in appropriate places, and *QUOTE is written to with false
+   to suppress pp_format's trailing close quote so that e.g.
+     foo_typedef {aka underlying_foo} {enum}
+   can be printed by "%qT" as:
+     `foo_typedef' {aka `underlying_foo'} {enum}
+   rather than:
+     `foo_typedef {aka underlying_foo} {enum}'
+   When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
+   then a leading open quote will be added, whereas if POSTPROCESSED is false
+   (for handling %T) then any leading quote has already been added by
+   pp_format, or is not needed due to QUOTE being NULL (for template arguments
+   within %H and %I).
+
+   SHOW_COLOR is used to determine the colorization of any quotes that
+   are added.  */
+
 static const char *
-type_to_string (tree typ, int verbose)
+type_to_string (tree typ, int verbose, bool postprocessed, bool *quote,
+               bool show_color)
 {
   int flags = 0;
   if (verbose)
@@ -3153,7 +3173,19 @@ type_to_string (tree typ, int verbose)
   flags |= TFF_TEMPLATE_HEADER;
 
   reinit_cxx_pp ();
+
+  if (postprocessed && quote && *quote)
+    pp_begin_quote (cxx_pp, show_color);
+
+  struct obstack *ob = pp_buffer (cxx_pp)->obstack;
+  int type_start, type_len;
+  type_start = obstack_object_size (ob);
+
   dump_type (cxx_pp, typ, flags);
+
+  /* Remember the end of the initial dump.  */
+  type_len = obstack_object_size (ob) - type_start;
+
   /* 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
@@ -3162,21 +3194,44 @@ type_to_string (tree typ, int verbose)
       && !uses_template_parms (typ))
     {
       int aka_start, aka_len; char *p;
-      struct obstack *ob = pp_buffer (cxx_pp)->obstack;
-      /* Remember the end of the initial dump.  */
-      int len = obstack_object_size (ob);
       tree aka = strip_typedefs (typ);
+      if (quote && *quote)
+       pp_end_quote (cxx_pp, show_color);
       pp_string (cxx_pp, " {aka");
       pp_cxx_whitespace (cxx_pp);
+      if (quote && *quote)
+       pp_begin_quote (cxx_pp, show_color);
       /* And remember the start of the aka dump.  */
       aka_start = obstack_object_size (ob);
       dump_type (cxx_pp, aka, flags);
       aka_len = obstack_object_size (ob) - aka_start;
+      if (quote && *quote)
+       pp_end_quote (cxx_pp, show_color);
       pp_right_brace (cxx_pp);
       p = (char*)obstack_base (ob);
-      /* If they are identical, cut off the aka with a NUL.  */
-      if (len == aka_len && memcmp (p, p+aka_start, len) == 0)
-       p[len] = '\0';
+      /* If they are identical, cut off the aka by unwinding the obstack.  */
+      if (type_len == aka_len
+         && memcmp (p + type_start, p+aka_start, type_len) == 0)
+       {
+         /* We can't add a '\0' here, since we may be adding a closing quote
+            below, and it would be hidden by the '\0'.
+            Instead, manually unwind the current object within the obstack
+            so that the insertion point is at the end of the type, before
+            the "' {aka".  */
+         int delta = type_start + type_len - obstack_object_size (ob);
+         gcc_assert (delta <= 0);
+         obstack_blank_fast (ob, delta);
+       }
+      else
+       if (quote)
+         /* No further closing quotes are needed.  */
+         *quote = false;
+    }
+
+  if (quote && *quote)
+    {
+      pp_end_quote (cxx_pp, show_color);
+      *quote = false;
     }
   return pp_ggc_formatted_text (cxx_pp);
 }
@@ -3634,7 +3689,7 @@ static const char *
 arg_to_string (tree arg, bool verbose)
 {
   if (TYPE_P (arg))
-    return type_to_string (arg, verbose);
+    return type_to_string (arg, verbose, true, NULL, false);
   else
     return expr_to_string (arg);
 }
@@ -3924,10 +3979,13 @@ cxx_format_postprocessor::handle (pretty_printer *pp)
        }
       else
        {
-         /* If the types were not comparable, they are printed normally,
-            and no difference tree is printed.  */
-         type_a_text = type_to_string (type_a.m_tree, type_a.m_verbose);
-         type_b_text = type_to_string (type_b.m_tree, type_b.m_verbose);
+         /* If the types were not comparable (or if only one of %H/%I was
+            provided), they are printed normally, and no difference tree
+            is printed.  */
+         type_a_text = type_to_string (type_a.m_tree, type_a.m_verbose,
+                                       true, &type_a.m_quote, show_color);
+         type_b_text = type_to_string (type_b.m_tree, type_b.m_verbose,
+                                       true, &type_b.m_quote, show_color);
        }
 
       if (type_a.m_quote)
@@ -4000,7 +4058,7 @@ defer_phase_2_of_type_diff (deferred_printed_type *deferred,
 static bool
 cp_printer (pretty_printer *pp, text_info *text, const char *spec,
            int precision, bool wide, bool set_locus, bool verbose,
-           bool quoted, const char **buffer_ptr)
+           bool *quoted, const char **buffer_ptr)
 {
   gcc_assert (pp->m_format_postprocessor);
   cxx_format_postprocessor *postprocessor
@@ -4043,7 +4101,12 @@ cp_printer (pretty_printer *pp, text_info *text, const char *spec,
     case 'P': result = parm_to_string (next_int);              break;
     case 'Q': result = op_to_string (true, next_tcode);                break;
     case 'S': result = subst_to_string (next_tree);            break;
-    case 'T': result = type_to_string (next_tree, verbose);    break;
+    case 'T':
+      {
+       result = type_to_string (next_tree, verbose, false, quoted,
+                                pp_show_color (pp));
+      }
+      break;
     case 'V': result = cv_to_string (next_tree, verbose);      break;
     case 'X': result = eh_spec_to_string (next_tree, verbose);  break;
 
@@ -4059,14 +4122,14 @@ cp_printer (pretty_printer *pp, text_info *text, const char *spec,
     case 'H':
       {
        defer_phase_2_of_type_diff (&postprocessor->m_type_a, next_tree,
-                                   buffer_ptr, verbose, quoted);
+                                   buffer_ptr, verbose, *quoted);
        return true;
       }
 
     case 'I':
       {
        defer_phase_2_of_type_diff (&postprocessor->m_type_b, next_tree,
-                                   buffer_ptr, verbose, quoted);
+                                   buffer_ptr, verbose, *quoted);
        return true;
       }
 
index 30e033afa399e98a9e9c589b9870c050684cf61e..cf1b320a73479e751703794c3408db4b78981db9 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-22  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c++/62170
+       * error.c (gfc_notify_std): Convert "quoted" param from bool to
+       bool *.
+
 2017-11-22  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/36313
index 3ad1cf9ff25c08960f528c609198cab5e9e13e8d..2cece498b319b979a374a7a7e79079759068e35e 100644 (file)
@@ -918,7 +918,7 @@ gfc_notify_std (int std, const char *gmsgid, ...)
 static bool
 gfc_format_decoder (pretty_printer *pp, text_info *text, const char *spec,
                    int precision, bool wide, bool set_locus, bool hash,
-                   bool quoted, const char **buffer_ptr)
+                   bool *quoted, const char **buffer_ptr)
 {
   switch (*spec)
     {
index e66d898a645ee3e412c8fbc742b40252492fd145..1fbd2fe045f488289f621f3be6357388778c667b 100644 (file)
@@ -1209,10 +1209,7 @@ pp_format (pretty_printer *pp, text_info *text)
       gcc_assert (!wide || precision == 0);
 
       if (quote)
-       {
-         pp_string (pp, open_quote);
-         pp_string (pp, colorize_start (pp_show_color (pp), "quote"));
-       }
+       pp_begin_quote (pp, pp_show_color (pp));
 
       switch (*p)
        {
@@ -1345,19 +1342,21 @@ pp_format (pretty_printer *pp, text_info *text)
          {
            bool ok;
 
+           /* Call the format decoder.
+              Pass the address of "quote" so that format decoders can
+              potentially disable printing of the closing quote
+              (e.g. when printing "'TYPEDEF' aka 'TYPE'" in the C family
+              of frontends).  */
            gcc_assert (pp_format_decoder (pp));
            ok = pp_format_decoder (pp) (pp, text, p,
-                                        precision, wide, plus, hash, quote,
+                                        precision, wide, plus, hash, &quote,
                                         formatters[argno]);
            gcc_assert (ok);
          }
        }
 
       if (quote)
-       {
-         pp_string (pp, colorize_stop (pp_show_color (pp)));
-         pp_string (pp, close_quote);
-       }
+       pp_end_quote (pp, pp_show_color (pp));
 
       obstack_1grow (&buffer->chunk_obstack, '\0');
       *formatters[argno] = XOBFINISH (&buffer->chunk_obstack, const char *);
@@ -1731,6 +1730,26 @@ pp_separate_with (pretty_printer *pp, char c)
   pp_space (pp);
 }
 
+/* Add a localized open quote, and if SHOW_COLOR is true, begin colorizing
+   using the "quote" color.  */
+
+void
+pp_begin_quote (pretty_printer *pp, bool show_color)
+{
+  pp_string (pp, open_quote);
+  pp_string (pp, colorize_start (show_color, "quote"));
+}
+
+/* If SHOW_COLOR is true, stop colorizing.
+   Add a localized close quote.  */
+
+void
+pp_end_quote (pretty_printer *pp, bool show_color)
+{
+  pp_string (pp, colorize_stop (show_color));
+  pp_string (pp, close_quote);
+}
+
 \f
 /* The string starting at P has LEN (at least 1) bytes left; if they
    start with a valid UTF-8 sequence, return the length of that
index 98296b1c20f40674cd0ae63dff12cc43eab9f3cf..9f6e2bb29a5563c4cd74b87c956c3a83deea36f7 100644 (file)
@@ -179,7 +179,7 @@ struct pp_wrapping_mode_t
    A client-supplied formatter returns true if everything goes well,
    otherwise it returns false.  */
 typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *,
-                           int, bool, bool, bool, bool, const char **);
+                           int, bool, bool, bool, bool *, const char **);
 
 /* Client supplied function used to decode formats.  */
 #define pp_format_decoder(PP) (PP)->format_decoder
@@ -386,6 +386,9 @@ extern void pp_write_text_to_stream (pretty_printer *);
 extern void pp_write_text_as_dot_label_to_stream (pretty_printer *, bool);
 extern void pp_maybe_space (pretty_printer *);
 
+extern void pp_begin_quote (pretty_printer *, bool);
+extern void pp_end_quote (pretty_printer *, bool);
+
 /* Switch into verbatim mode and return the old mode.  */
 static inline pp_wrapping_mode_t
 pp_set_verbatim_wrapping_ (pretty_printer *pp)
index aa4d09583feef743077b5628ab2d02ce3590a934..705625e4b4934be1ca2d69b4efc32fbe9d5a501e 100644 (file)
@@ -1,3 +1,23 @@
+2017-11-22  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c++/62170
+       * g++.dg/diagnostic/aka1.C: Update expected error messages to
+       reflect fixes to quoting.
+       * g++.dg/diagnostic/aka2.C: New test case.
+       * g++.dg/parse/error55.C: Update expected error messages to
+       reflect fixes to quoting.
+       * gcc.dg/diag-aka-1.c: Likewise.
+       * gcc.dg/diag-aka-2.c: New test case.
+       * gcc.dg/pr13804-1.c: Update expected error messages to reflect
+       fixes to quoting.
+       * gcc.dg/pr56980.c: Likewise.
+       * gcc.dg/pr65050.c: Likewise.
+       * gcc.dg/redecl-14.c: Likewise.
+       * gcc.dg/utf16-4.c Likewise.
+       * gcc.target/i386/sse-vect-types.c (__m128d): Likewise.
+       * obj-c++.dg/invalid-type-1.mm: Likewise.
+       * objc.dg/proto-lossage-4.m: Likewise.
+
 2017-11-22  Uros Bizjak  <ubizjak@gmail.com>
 
        * lib/target-supports.exp (check_effective_target_bswap16): Remove
index 37f8df9399d251128fbf8645ab17f61217009239..cb314fb6536b890573f4d2405d5e7c6466a70c74 100644 (file)
@@ -12,4 +12,4 @@ void A::f() {
 typedef A B;
 
 // We do want an aka for a real typedef.
-B b = 0;                       // { dg-error "B .aka A." }
+B b = 0;                       // { dg-error "'B' {aka 'A'}" }
diff --git a/gcc/testsuite/g++.dg/diagnostic/aka2.C b/gcc/testsuite/g++.dg/diagnostic/aka2.C
new file mode 100644 (file)
index 0000000..a43f9e3
--- /dev/null
@@ -0,0 +1,32 @@
+/* Verify that the "aka" descriptions for typedefs are correctly
+   quoted (PR 62170).  */
+
+/* Exercise %H and %I.  */
+
+typedef struct s1 t1;
+typedef struct s2 {int i;} t2;
+
+int foo(t1 *);
+
+void test_1 () {
+  t2 pos;
+
+  foo (&pos); // { dg-error "cannot convert 't2\\*' {aka 's2\\*'} to 't1\\*' {aka 's1\\*'} for argument '1' to 'int foo\\(t1\\*\\)'" }
+}
+
+/* Exercise %T.  */
+
+typedef struct s3
+{  
+  void m3 ();
+} t3;
+
+void test_2 (const s3 *ptr)
+{
+  ptr->m3 (); // { dg-error "passing 'const s3' as 'this' argument discards qualifiers" }
+}
+
+void test_3 (const t3 *ptr)
+{
+  ptr->m3 (); // { dg-error "passing 'const t3' {aka 'const s3'} as 'this' argument discards qualifiers" }
+}
index 24cca50b2c3ed785f97d881bd6d1591a3bfd1091..70af85d91bcc2bd0d992e371e5eb3b90908cee35 100644 (file)
@@ -3,5 +3,5 @@
 class A { };
 typedef A B;
 void foo (B &a) {
-  a.x();  // { dg-error "'B {aka class A}' has no member named 'x'" }
+  a.x();  // { dg-error "'B' {aka 'class A'} has no member named 'x'" }
 }
index 87bc75753e4f797bbaf6cd4dc099c4bc46743599..fde4ca7c74312e75931e52e1849b8254bde2cc21 100644 (file)
@@ -10,7 +10,7 @@ typedef int IA[];
 typedef IA *IAP;
 extern IAP arr[];
 
-void fn1 (B *); /* { dg-message "expected .B \\* {aka struct A \\*}. but argument is of type .struct B \\*." } */
+void fn1 (B *); /* { dg-message "expected 'B \\*' {aka 'struct A \\*'} but argument is of type 'struct B \\*'" } */
 void fn2 (TFC *);
 
 void 
@@ -24,6 +24,6 @@ bar (B *b, int *i)
 int
 foo (void *a)
 {
-  T *t = a; /* { dg-warning "request for implicit conversion from .void \\*. to .T \\* {aka struct T \\*}. not" } */
+  T *t = a; /* { dg-warning "request for implicit conversion from 'void \\*' to 'T \\*' {aka 'struct T \\*'} not" } */
   return t->i;
 }
diff --git a/gcc/testsuite/gcc.dg/diag-aka-2.c b/gcc/testsuite/gcc.dg/diag-aka-2.c
new file mode 100644 (file)
index 0000000..a4b2242
--- /dev/null
@@ -0,0 +1,12 @@
+/* Verify that the "aka" descriptions for typedefs are correctly
+   quoted (PR 62170).  */
+
+typedef struct s1 t1;
+
+int foo(t1 *); /* { dg-message "expected 't1 \\*' {aka 'struct s1 \\*'} but argument is of type 't2 \\*' {aka 'struct s2 \\*'}" } */
+
+int bar() {
+  typedef struct s2 {int i;} t2;
+  t2 pos;
+  return foo(&pos); /* { dg-error "incompatible pointer type" } */
+}
index 65b238a9b8fefdc6c4b8d6c510e9c262e8f925fc..5fc17f427cb0301a09bb1aa01e1ed86f7933f0e8 100644 (file)
@@ -20,9 +20,9 @@ void
 f (void)
 {
   x0.c; /* { dg-error "'struct s0' has no member named 'c'" } */
-  x1.c; /* { dg-error "'S0 {aka struct s0}' has no member named 'c'" } */
+  x1.c; /* { dg-error "'S0' {aka 'struct s0'} has no member named 'c'" } */
   x2.c; /* { dg-error "'union u0' has no member named 'c'" } */
-  x3.c; /* { dg-error "'U0 {aka union u0}' has no member named 'c'" } */
+  x3.c; /* { dg-error "'U0' {aka 'union u0'} has no member named 'c'" } */
   x4->c; /* { dg-error "'struct s0' has no member named 'c'" } */
   x5->c; /* { dg-error "'union u0' has no member named 'c'" } */
 }
index 27405efac4e3df1f46f10a92f21245032a36a40d..5303c6135fa78cda5eeebb01b2b144f8425a54f7 100644 (file)
@@ -5,12 +5,12 @@ typedef struct A { int i; } B;
 typedef union U { int i; } V;
 typedef enum E { G } F;
 
-void foo_s (struct A); /* { dg-message "expected .struct A. but argument is of type .B \\* {aka struct A \\*}." } */
-void foo_u (union U); /* { dg-message "expected .union U. but argument is of type .V \\* {aka union U \\*}." } */
-void foo_e (enum E); /* { dg-message "expected .enum E. but argument is of type .F \\* {aka enum E \\*}." } */
-void foo_sp (B *); /* { dg-message "expected .B \\* {aka struct A \\*}. but argument is of type .struct B \\*." } */
-void foo_up (V *); /* { dg-message "expected .V \\* {aka union U \\*}. but argument is of type .union V \\*." } */
-void foo_ep (F *); /* { dg-message "expected .F \\* {aka enum E \\*}. but argument is of type .enum F \\*." } */
+void foo_s (struct A); /* { dg-message "expected .struct A. but argument is of type 'B \\*' {aka 'struct A \\*'}" } */
+void foo_u (union U); /* { dg-message "expected .union U. but argument is of type 'V \\*' {aka 'union U \\*'}" } */
+void foo_e (enum E); /* { dg-message "expected .enum E. but argument is of type 'F \\*' {aka 'enum E \\*'}" } */
+void foo_sp (B *); /* { dg-message "expected 'B \\*' {aka 'struct A \\*'} but argument is of type .struct B \\*." } */
+void foo_up (V *); /* { dg-message "expected 'V \\*' {aka 'union U \\*'} but argument is of type .union V \\*." } */
+void foo_ep (F *); /* { dg-message "expected 'F \\*' {aka 'enum E \\*'} but argument is of type .enum F \\*." } */
 
 void 
 bar (B *b, V *v, F *f)
index 0822a99dfdaeecf815185353d52f89f0f208c919..e29559d3e73fe880a104b2af65b254b08ac2ac0f 100644 (file)
@@ -2,9 +2,9 @@
 /* { dg-do compile } */
 
 typedef int A[];
-struct S { int i; A a[5]; } s; /* { dg-error "array type has incomplete element type .A {aka int\\\[\\\]}." } */
+struct S { int i; A a[5]; } s; /* { dg-error "array type has incomplete element type 'A' {aka 'int\\\[\\\]'}" } */
 extern void foo (int p[2][]); /* { dg-error "array type has incomplete element type .int\\\[\\\]." } */
-extern void bar (A p[2]); /* { dg-error "array type has incomplete element type .A {aka int\\\[\\\]}." } */
+extern void bar (A p[2]); /* { dg-error "array type has incomplete element type 'A' {aka 'int\\\[\\\]'}" } */
 
 void
 foo (int p[2][]) /* { dg-error "array type has incomplete element type .int\\\[\\\]." } */
@@ -12,7 +12,7 @@ foo (int p[2][]) /* { dg-error "array type has incomplete element type .int\\\[\
 }
 
 void
-bar (A p[2]) /* { dg-error "array type has incomplete element type .A {aka int\\\[\\\]}." } */
+bar (A p[2]) /* { dg-error "array type has incomplete element type 'A' {aka 'int\\\[\\\]'}" } */
 {
 }
 
@@ -20,4 +20,4 @@ struct T;
 struct T t[5]; /* { dg-error "array type has incomplete element type .struct T." } */
 struct U u[] = { { "abc" } }; /* { dg-error "array type has incomplete element type .struct U." } */
 typedef struct T TT;
-TT tt[5]; /* { dg-error "array type has incomplete element type .TT {aka struct T}." } */
+TT tt[5]; /* { dg-error "array type has incomplete element type 'TT' {aka 'struct T'}" } */
index 97003c1234b85152fd5b156ba6b61b1cc3b4d168..1bf1d96eadc13749682cd4467844d30994da8063 100644 (file)
@@ -18,5 +18,5 @@ f (void)
   }
   extern IAP a[];
   extern IAP a[5];
-  sizeof (*a[0]); /* { dg-error "invalid application of 'sizeof' to incomplete type 'IA {aka int\\\[\\\]}'" } */
+  sizeof (*a[0]); /* { dg-error "invalid application of 'sizeof' to incomplete type 'IA' {aka 'int\\\[\\\]'}" } */
 }
index e2f115ebc813ba380718254db699db8ef96e532b..4b203877dde73eb12191a875bd15b21250bab4f4 100644 (file)
@@ -12,7 +12,7 @@ char16_t      c2 = u'\U00064321';     /* { dg-warning "constant too long" } */
 char16_t       c3 = 'a';
 char16_t       c4 = U'a';
 char16_t       c5 = U'\u2029';
-char16_t       c6 = U'\U00064321';     /* { dg-warning "conversion from .(long )?unsigned int. to .char16_t {aka short unsigned int}. changes value from .410401. to .17185." } */
+char16_t       c6 = U'\U00064321';     /* { dg-warning "conversion from .(long )?unsigned int. to 'char16_t' {aka 'short unsigned int'} changes value from .410401. to .17185." } */
 char16_t       c7 = L'a';
 char16_t       c8 = L'\u2029';
 char16_t       c9 = L'\U00064321';     /* { dg-warning "conversion" "" { target { 4byte_wchar_t } } } */
index 9cb6f3e07cd45fe6fa8c9cd68af71e3e605f11e7..ac4ece400eead2880668632f9bfd4c97dd14e512 100644 (file)
@@ -10,4 +10,4 @@ __m128d foo1(__m128d z, __m128d  a, int N) {
   }
   return a;
 }
-/* { dg-message "note: expected '\[^'\n\]*' but argument is of type '\[^'\n\]*'" "note: expected" { target *-*-* } 0 } */
+/* { dg-message "note: expected '.*'.* but argument is of type '.*'" "note: expected" { target *-*-* } 0 } */
index cb2138fd38ebdd60db0cccb4c6d370b2e4e43508..59c86667995986a549cd3bdd69c9b17bf967bd41 100644 (file)
@@ -18,8 +18,8 @@ id <MyProtocol> object; /* This is fine.  */
 
 AClass <MyProtocol> *object1; /* This is fine.  */
 
-Integer <MyProtocol> *object2; /* { dg-error ".Integer {aka int}. 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 *-*-* } .-1 } */
 
-Integer <NonExistingProtocol> *object3; /* { dg-error ".Integer {aka int}. 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 *-*-* } .-1 } */
index c9c80b7c4273cb40cb6812628e4afbac87b21ee0..182e92d94b202a5e572f45b658724dda47d4e0a1 100644 (file)
@@ -28,13 +28,13 @@ long foo(void) {
   receiver += [receiver anotherValue]; /* { dg-warning "invalid receiver type .intptr_t." } */
 
   receiver += [(Obj *)receiver someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */
-/* { dg-warning "assignment to 'intptr_t {aka (long )?int}' from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
+/* { dg-warning "assignment to 'intptr_t' {aka '(long )?int'} from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
 
   receiver += [(Obj *)receiver anotherValue];
   receiver += [(Obj <Proto> *)receiver someValue];
   receiver += [(Obj <Proto> *)receiver anotherValue];
   receiver += [objrcvr someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */
-/* { dg-warning "assignment to 'intptr_t {aka (long )?int}' from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
+/* { dg-warning "assignment to 'intptr_t' {aka '(long )?int'} from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
 
   receiver += [objrcvr anotherValue];
   receiver += [(Obj <Proto> *)objrcvr someValue];
@@ -42,7 +42,7 @@ long foo(void) {
   receiver += [objrcvr2 someValue];
   receiver += [objrcvr2 anotherValue];
   receiver += [(Obj *)objrcvr2 someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */
-/* { dg-warning "assignment to 'intptr_t {aka (long )?int}' from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
+/* { dg-warning "assignment to 'intptr_t' {aka '(long )?int'} from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
 
   receiver += [(Obj *)objrcvr2 anotherValue];
 
index 023e896a34a524dda37c6acd14cda73ed5538e66..c80ae54162079a1a5aaff84b4d153f3369e872c4 100644 (file)
@@ -246,7 +246,7 @@ virt_loc_aware_diagnostic_finalizer (diagnostic_context *context,
 bool
 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
                      int precision, bool wide, bool set_locus, bool hash,
-                     bool, const char **)
+                     bool *, const char **)
 {
   tree t;
 
index 85aa980aeb97d9702e7e873f5a2b426138f55149..e38bb44204ba0e226dbef7e051580147118d62de 100644 (file)
@@ -55,6 +55,6 @@ void virt_loc_aware_diagnostic_finalizer (diagnostic_context *,
 
 void tree_diagnostics_defaults (diagnostic_context *context);
 bool default_tree_printer (pretty_printer *, text_info *, const char *,
-                          int, bool, bool, bool, bool, const char **);
+                          int, bool, bool, bool, bool *, const char **);
 
 #endif /* ! GCC_TREE_DIAGNOSTIC_H */