From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19828 invoked by alias); 1 Jul 2011 18:07:03 -0000 Received: (qmail 19817 invoked by uid 22791); 1 Jul 2011 18:07:02 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_CX,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jul 2011 18:06:48 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p61I6X4q015293 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 1 Jul 2011 14:06:47 -0400 Received: from [127.0.0.1] (ovpn-113-148.phx2.redhat.com [10.3.113.148]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p61GVnwj006193; Fri, 1 Jul 2011 12:31:49 -0400 Message-ID: <4E0DF674.7000307@redhat.com> Date: Fri, 01 Jul 2011 18:07:00 -0000 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List CC: Gabriel Dos Reis Subject: C++ PATCH to improve 'aka's on type printing in diagnostics References: <4DF79CA1.7010001@redhat.com> In-Reply-To: <4DF79CA1.7010001@redhat.com> Content-Type: multipart/mixed; boundary="------------090103070102000904080806" Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-07/txt/msg00077.txt.bz2 This is a multi-part message in MIME format. --------------090103070102000904080806 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 709 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? --------------090103070102000904080806 Content-Type: text/x-patch; name="aka-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="aka-2.patch" Content-length: 1644 commit 27301c5f28e808c3a6ba6e5184a6968ad12fc939 Author: Jason Merrill 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; --------------090103070102000904080806--