+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)
+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
#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)
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;
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;
}
+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
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);
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. */
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)
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
&& !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);
}
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);
}
}
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)
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
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;
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;
}
+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
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)
{
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)
{
{
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, "e,
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 *);
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
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
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)
+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
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'}" }
--- /dev/null
+/* 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" }
+}
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'" }
}
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
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;
}
--- /dev/null
+/* 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" } */
+}
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'" } */
}
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)
/* { 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\\\[\\\]." } */
}
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\\\[\\\]'}" } */
{
}
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'}" } */
}
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\\\[\\\]'}" } */
}
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 } } } */
}
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 } */
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 } */
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];
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];
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;
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 */