From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12951 invoked by alias); 4 Jul 2011 21:29:15 -0000 Received: (qmail 12943 invoked by uid 22791); 4 Jul 2011 21:29:15 -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; Mon, 04 Jul 2011 21:28:55 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p64LSroe008884 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 4 Jul 2011 17:28:53 -0400 Received: from [127.0.0.1] (ovpn-113-69.phx2.redhat.com [10.3.113.69]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p64LSqla005100; Mon, 4 Jul 2011 17:28:53 -0400 Message-ID: <4E123094.6000009@redhat.com> Date: Mon, 04 Jul 2011 21:29: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: Gabriel Dos Reis CC: gcc-patches List Subject: Re: C++ PATCH to improve 'aka's on type printing in diagnostics References: <4DF79CA1.7010001@redhat.com> <4E0DF674.7000307@redhat.com> <87mxgtes9c.fsf@gauss.cs.tamu.edu> In-Reply-To: <87mxgtes9c.fsf@gauss.cs.tamu.edu> Content-Type: multipart/mixed; boundary="------------030500060707010403000907" 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/msg00221.txt.bz2 This is a multi-part message in MIME format. --------------030500060707010403000907 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 181 I thought of a different way to do it that would stay encapsulated in type_as_string, so this is the version I'm going to check in. Tested x86_64-pc-linux-gnu, applying to trunk. --------------030500060707010403000907 Content-Type: text/x-patch; name="aka-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="aka-2.patch" Content-length: 1984 commit 689a3e58f4eebbcdafec81f06e8af699045fff3a Author: Jason Merrill Date: Fri Jul 1 00:16:46 2011 -0400 * error.c (type_to_string): Avoid redundant akas. diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 7c90ec4..664b918 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -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); } diff --git a/gcc/testsuite/g++.dg/diagnostic/aka1.C b/gcc/testsuite/g++.dg/diagnostic/aka1.C new file mode 100644 index 0000000..37f8df9 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/aka1.C @@ -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." } --------------030500060707010403000907--