From patchwork Mon Jul 13 13:41:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 494578 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1C0D01402AB for ; Mon, 13 Jul 2015 23:42:03 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=IRjObIYY; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=mZoHCEtjH8SESjc77EDLSo+0sWuh2+fMNtc00R1coPk /0a2G+Ff+X3wMz4sWcd498zgO13JzQn3r9ZR1PlaE1w9dN5/O8RMJ+WkU8rT2Myk f9WlIwgew9/UMVXrGinWu7gXDdWkOcaOOmXQcDgefTCAJi2RZ94jRBsMyHzz85n8 = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=agHB1Ol8YApjk0ApJ1eO3fRaWGk=; b=IRjObIYY2JtCynPQ4 itWAZa0rdF034KDPVLAnD4I3z5lO+Aflc4VngDJ4S7eBb0FaFTxLqDby7l8m/xPD B7JIez6mXuu4yHSHNvKg6MwTeJeUHkuVMJqgIZuW2TYmKDbbn+dbvRda8Gmcafwv YBiFbPkE8RhhMy+IfrHt6q62tU= Received: (qmail 4433 invoked by alias); 13 Jul 2015 13:41:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 4414 invoked by uid 89); 13 Jul 2015 13:41:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_05, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 13 Jul 2015 13:41:49 +0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t6DDfjRw003939 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 13 Jul 2015 13:41:46 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t6DDfjf2002424 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 13 Jul 2015 13:41:45 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t6DDfj4C016303; Mon, 13 Jul 2015 13:41:45 GMT Received: from [192.168.1.4] (/79.8.231.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2015 06:41:44 -0700 Message-ID: <55A3C015.3070105@oracle.com> Date: Mon, 13 Jul 2015 15:41:41 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] Prefer error + inform to two errors in check_template_shadow X-IsSubscribed: yes Hi, while going thru the pending template template issues, I noticed that check_template_shadow still emits two errors. I believe we also want to simply use D instead of #D for template parameters, that avoids the nit about class T vs template T which could be slightly confusing to novices, I suppose. Tested x86_64-linux. Thanks, Paolo. ////////////////////////////// /cp 2015-07-13 Paolo Carlini * pt.c (check_template_shadow): Emit error + inform instead of two errors. /testsuite 2015-07-13 Paolo Carlini * g++.dg/template/crash81.C: Adjust for error + inform change. * g++.dg/template/pr58878.C: Likewise. * g++.dg/template/shadow1.C: Likewise. * g++.dg/template/shadow2.C: Likewise. * g++.old-deja/g++.benjamin/tem03.C: Likewise. * g++.old-deja/g++.benjamin/tem04.C: Likewise. * g++.old-deja/g++.brendan/crash7.C: Likewise. * g++.old-deja/g++.pt/shadow2.C: Likewise. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 225730) +++ cp/pt.c (working copy) @@ -3661,8 +3661,13 @@ check_template_shadow (tree decl) if (DECL_SELF_REFERENCE_P (decl)) return false; - error ("declaration of %q+#D", decl); - error (" shadows template parm %q+#D", olddecl); + if (DECL_TEMPLATE_PARM_P (decl)) + error ("declaration of template parameter %q+D shadows " + "template parameter", decl); + else + error ("declaration of %q+#D shadows template parameter", decl); + inform (DECL_SOURCE_LOCATION (olddecl), + "template parameter %qD declared here", olddecl); return false; } Index: testsuite/g++.dg/template/crash81.C =================================================================== --- testsuite/g++.dg/template/crash81.C (revision 225730) +++ testsuite/g++.dg/template/crash81.C (working copy) @@ -3,6 +3,6 @@ struct A { template struct X; // { dg-error "'T' has not been declared" "T" } - // { dg-error "declaration of 'template struct A::X'" "A::X" { target *-*-* } 5 } - // { dg-error "shadows template parm 'int X'" "shadow" { target *-*-* } 5 } + // { dg-error "declaration of 'template struct A::X' shadows" "A::X" { target *-*-* } 5 } + // { dg-message "template parameter 'X'" "" { target *-*-* } 5 } }; Index: testsuite/g++.dg/template/pr58878.C =================================================================== --- testsuite/g++.dg/template/pr58878.C (revision 225730) +++ testsuite/g++.dg/template/pr58878.C (working copy) @@ -3,10 +3,10 @@ // Template-members of non-template class struct A { - template // { dg-error "shadows" } + template // { dg-message "template parameter" } void f() { - int t = 1; // { dg-error "declaration" } + int t = 1; // { dg-error "shadows" } } template @@ -13,39 +13,39 @@ struct A void g(); }; -template // { dg-error "shadows" } +template // { dg-message "template parameter" } void A::g() { - int t = 2; // { dg-error "declaration" } + int t = 2; // { dg-error "shadows" } } // (Non-template) Members of template class -template // { dg-error "shadows" } +template // { dg-message "template parameter" } struct B { void f() { - int t = 3; // { dg-error "declaration" } + int t = 3; // { dg-error "shadows" } } void g(); }; -template // { dg-error "shadows" } +template // { dg-message "template parameter" } void B::g() { - int t = 4; // { dg-error "declaration" } + int t = 4; // { dg-error "shadows" } } // Template members of template class -template // { dg-error "shadows" } +template // { dg-message "template parameter" } struct C { - template // { dg-error "shadows" } + template // { dg-message "template parameter" } void f() { - int t = 5; // { dg-error "declaration" } - int s = 6; // { dg-error "declaration" } + int t = 5; // { dg-error "shadows" } + int s = 6; // { dg-error "shadows" } } template @@ -52,10 +52,10 @@ struct C void g(); }; -template // { dg-error "shadows" } -template // { dg-error "shadows" } +template // { dg-message "template parameter" } +template // { dg-message "template parameter" } void C::g() { - int t = 7; // { dg-error "declaration" } - int s = 8; // { dg-error "declaration" } + int t = 7; // { dg-error "shadows" } + int s = 8; // { dg-error "shadows" } } Index: testsuite/g++.dg/template/shadow1.C =================================================================== --- testsuite/g++.dg/template/shadow1.C (revision 225730) +++ testsuite/g++.dg/template/shadow1.C (working copy) @@ -1,4 +1,4 @@ // PR c++/58632 -template class A> // { dg-message "shadows" } -class A {}; // { dg-error "declaration" } +template class A> // { dg-message "template parameter" } +class A {}; // { dg-error "shadows" } Index: testsuite/g++.dg/template/shadow2.C =================================================================== --- testsuite/g++.dg/template/shadow2.C (revision 225730) +++ testsuite/g++.dg/template/shadow2.C (working copy) @@ -1,3 +1,3 @@ -template class B> // { dg-error "declaration of 'class A'" } +template class B> // { dg-error "declaration of template parameter 'A' shadows" } class X; Index: testsuite/g++.old-deja/g++.benjamin/tem03.C =================================================================== --- testsuite/g++.old-deja/g++.benjamin/tem03.C (revision 225730) +++ testsuite/g++.old-deja/g++.benjamin/tem03.C (working copy) @@ -18,7 +18,7 @@ // 01 // declared friend template -template // { dg-error "" } .* +template // { dg-message "" } .* class Xone { protected: T4* next; @@ -38,7 +38,7 @@ class Xone { // 02 // nested template class -template // { dg-error "" } .* +template // { dg-message "" } .* class Xtwo { protected: T6* next; @@ -58,7 +58,7 @@ class Xtwo { // 03 // member templates -template // { dg-error "" } .* +template // { dg-message "" } .* class Xthree { protected: T8* next; @@ -80,7 +80,7 @@ class Xthree { // 04 // local names (14.6.1 p 4) -template struct Xfour {// { dg-error "" } .* +template struct Xfour {// { dg-message "" } .* int T10; // { dg-error "" } .* void f(){ char T10; // { dg-error "declaration of 'char T10'" } @@ -94,7 +94,7 @@ template struct Xfive { void f(); }; -template void Xfive::f() {// { dg-error "" } .* +template void Xfive::f() {// { dg-message "" } .* int T13; // { dg-error "" } .* int T12; //should be ok } @@ -116,7 +116,7 @@ template class T12; // { dg-error "" } // 08 // with multiple template params, and second (third) one is redeclared -template class Xseven { // { dg-error "" } .* +template class Xseven { // { dg-message "" } .* private: char T161; // { dg-error "" } .* public: @@ -123,7 +123,7 @@ template class T12; // { dg-error "" } template friend bool fooy(U u); - template // { dg-error "declaration of 'class T161'" } + template // { dg-error "declaration of template parameter 'T161'" } friend bool foo(T161 u) { Xseven obj; @@ -158,7 +158,7 @@ struct S1 // 10 // check for non-type parameters, should still be able to redeclare? // local names (14.6.1 p 4) -template class Xten {// { dg-error "" } .* +template class Xten {// { dg-message "" } .* float i; // { dg-error "" } .* }; @@ -165,7 +165,7 @@ struct S1 // 11 // declared friend template, non-type parameters -template // { dg-error "" } .* +template // { dg-message "" } .* class Xeleven { public: template friend bool isequal (Xeleven<5> lhs, Xeleven<5> rhs); // { dg-error "" } .* @@ -175,7 +175,7 @@ class Xeleven { // 12 // nested template class, non-type parameters -template // { dg-error "" } .* +template // { dg-message "" } .* class Xtwelve { public: template class nested {// { dg-error "" } . @@ -188,7 +188,7 @@ class Xtwelve { // 13 // member templates, non-type parameters -template // { dg-error "" } .* +template // { dg-message "" } .* struct Xthirteen { template long comp_ge(long test) {// { dg-error "" } . long local_value; Index: testsuite/g++.old-deja/g++.benjamin/tem04.C =================================================================== --- testsuite/g++.old-deja/g++.benjamin/tem04.C (revision 225730) +++ testsuite/g++.old-deja/g++.benjamin/tem04.C (working copy) @@ -18,7 +18,7 @@ // 14 // declared friend template (v3, template type parameters) -template // { dg-error "" } .* +template // { dg-message "" } .* class Xfourteen { protected: T4 value; @@ -31,7 +31,7 @@ class Xfourteen { // 15 // nested template class (v3, template type parameters) -template // { dg-error "" } .* +template // { dg-message "" } .* class Xfifteen { protected: T6 value; @@ -48,7 +48,7 @@ class Xfifteen { // 16 // member templates (v3, template type parameters) -template // { dg-error "" } .* +template // { dg-message "" } .* class Xsixteen { protected: T8 value; @@ -88,7 +88,7 @@ class Xseventeen { // 18 // more template template redecl tests -template class C12>// { dg-error "" } .* +template class C12>// { dg-message "" } .* class Xeighteen { protected: C12 value; @@ -98,7 +98,7 @@ class Xeighteen { // 19 // more template template redecl tests -template class C14>// { dg-error "" } .* +template class C14>// { dg-message "" } .* class Xnineteen{ protected: C14 value; @@ -137,7 +137,7 @@ template struct Xtwenty { // non-type template parameters v1: enum enum my_enum {my_A = 45, my_B, my_C}; -template class Xtwentyone {// { dg-error "" } .* +template class Xtwentyone {// { dg-message "" } .* float T18; // { dg-error "" } .* }; @@ -149,7 +149,7 @@ struct base { int ret_gcount() {return gcount;} }; -template class Xtwentytwo {// { dg-error "" } .* +template class Xtwentytwo {// { dg-message "" } .* float b; // { dg-error "" } .* }; @@ -156,7 +156,7 @@ struct base { // 23 // non-type template parameters v2: reference to object -template class Xtwentythree {// { dg-error "" } .* +template class Xtwentythree {// { dg-message "" } .* float b2; // { dg-error "" } .* }; @@ -163,7 +163,7 @@ struct base { // 24 // non-type template parameters v3: pointer to member -template class Xtwentyfour {// { dg-error "" } .* +template class Xtwentyfour {// { dg-message "" } .* float b3; // { dg-error "" } .* }; @@ -170,13 +170,8 @@ struct base { // 25 // non-type template parms that use push_class_level -template void f1() {// { dg-error "" } .* +template void f1() {// { dg-message "" } .* struct foo { enum T22 { un, du, toi }; // { dg-error "" } .* }; } - - - - - Index: testsuite/g++.old-deja/g++.brendan/crash7.C =================================================================== --- testsuite/g++.old-deja/g++.brendan/crash7.C (revision 225730) +++ testsuite/g++.old-deja/g++.brendan/crash7.C (working copy) @@ -13,7 +13,7 @@ class Vector int size () { return sz; } }; -template// { dg-error "" } previous definition of T +template// { dg-message "" } previous definition of T struct Comparator { typedef T T;// { dg-error "" } use of template type T in typedef to T Index: testsuite/g++.old-deja/g++.pt/shadow2.C =================================================================== --- testsuite/g++.old-deja/g++.pt/shadow2.C (revision 225730) +++ testsuite/g++.old-deja/g++.pt/shadow2.C (working copy) @@ -1,7 +1,7 @@ // { dg-do assemble } // Origin: Jason Merrill -template struct A { // { dg-error "" } shadowed parameter +template struct A { // { dg-message "" } shadowed parameter struct B { void T(); // { dg-error "" } shadows template parameter };