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?
commit 27301c5f28e808c3a6ba6e5184a6968ad12fc939 Author: Jason Merrill <ja...@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;