From patchwork Sun Aug 25 10:52:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 269694 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 5C7322C00BC for ; Sun, 25 Aug 2013 20:52:42 +1000 (EST) 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=YFyzLVpxhcDk8LO9nTvs7y95cU+ewDczqHe7R4cZkGS Qq0UUJA0qjlhcoxrpoPd1XP3nOwE81oFxu/EU/FylfkLWJcqw7VvaAGUDsjMbR/H E6ZWXVrEIcu/zg207XNHR6FjjiDxsc35U24ZF6k4H2eVqkQycBq3wzbZVOYZUk3E = 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=PERPzaawdc2/x0o2+UebTHneMvQ=; b=l2Vpea4h27B4rnY43 RH5J0jXuBth06q3BaHVi+Bt15g8Hm6DQX7aSxVzs3iNL9Njz+aTjAodMFYX2l2lz Jx8Du4PDhinX622dqmB5TtrKLLmXOM87eQMtEFqC1eprvGj5oULQRDsTyiG2GgZ1 ui+0ze/t+gupHk1mqXuKVYe3GA= Received: (qmail 8504 invoked by alias); 25 Aug 2013 10:52:33 -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 8486 invoked by uid 89); 25 Aug 2013 10:52:33 -0000 X-Spam-SWARE-Status: No, score=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.2 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with (AES256-SHA encrypted) ESMTPS; Sun, 25 Aug 2013 10:52:32 +0000 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r7PAqSk8032390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 25 Aug 2013 10:52:30 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r7PAqRkE008431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 25 Aug 2013 10:52:28 GMT Received: from abhmt108.oracle.com (abhmt108.oracle.com [141.146.116.60]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r7PAqQsI018839; Sun, 25 Aug 2013 10:52:27 GMT Received: from poldo4.casa (/79.25.197.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 25 Aug 2013 03:52:26 -0700 Message-ID: <5219E1E8.2020707@oracle.com> Date: Sun, 25 Aug 2013 12:52:24 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 54485 X-Virus-Found: No Hi, this bug, filed by Diego, is about 8.3.6/6, where member functions of class templates, at variance with plain classes, do not admit default arguments on the out-of-class redeclaration. Tested x86_64-linux. Thanks, Paolo. ////////////////////////// /cp 2013-08-25 Paolo Carlini PR c++/54485 * decl.c (duplicate_decls): Enforce 8.3.6/6 about default arguments for member functions of class templates. /testsuite 2013-08-25 Paolo Carlini PR c++/54485 * g++.dg/other/default8.C: New. * g++.dg/tc1/dr217.C: Remove xfail. * g++.dg/other/default5.C: Adjust. * g++.old-deja/g++.mike/p1989.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 201977) +++ cp/decl.c (working copy) @@ -1686,25 +1686,47 @@ duplicate_decls (tree newdecl, tree olddecl, bool if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); - for (; t1 && t1 != void_list_node; - t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) - if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) - { - if (1 == simple_cst_equal (TREE_PURPOSE (t1), - TREE_PURPOSE (t2))) + if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE + && CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (newdecl))) + { + /* C++11 8.3.6/6. + Default arguments for a member function of a class template + shall be specified on the initial declaration of the member + function within the class template. */ + for (; t2 && t2 != void_list_node; t2 = TREE_CHAIN (t2)) + if (TREE_PURPOSE (t2)) { - permerror (input_location, "default argument given for parameter %d of %q#D", - i, newdecl); - permerror (input_location, "after previous specification in %q+#D", olddecl); + permerror (input_location, + "redeclaration of %q#D may not have default " + "arguments", newdecl); + break; } - else + } + else + { + for (; t1 && t1 != void_list_node; + t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) + if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) { - error ("default argument given for parameter %d of %q#D", - i, newdecl); - error ("after previous specification in %q+#D", - olddecl); + if (1 == simple_cst_equal (TREE_PURPOSE (t1), + TREE_PURPOSE (t2))) + { + permerror (input_location, + "default argument given for parameter %d " + "of %q#D", i, newdecl); + permerror (input_location, + "after previous specification in %q+#D", + olddecl); + } + else + { + error ("default argument given for parameter %d " + "of %q#D", i, newdecl); + error ("after previous specification in %q+#D", + olddecl); + } } - } + } } } Index: testsuite/g++.dg/other/default5.C =================================================================== --- testsuite/g++.dg/other/default5.C (revision 201977) +++ testsuite/g++.dg/other/default5.C (working copy) @@ -43,5 +43,5 @@ template struct B void F2(int, int, int = 0); }; -template void B::F1(int, int = 0, int) {} -template void B::F2(int = 0, int, int) {} // { dg-error "default" } +template void B::F1(int, int = 0, int) {} // { dg-error "default arguments" } +template void B::F2(int = 0, int, int) {} // { dg-error "default arguments|parameter 2" } Index: testsuite/g++.dg/other/default8.C =================================================================== --- testsuite/g++.dg/other/default8.C (revision 0) +++ testsuite/g++.dg/other/default8.C (working copy) @@ -0,0 +1,43 @@ +// PR c++54485 + +template +class K1 +{ + int fn(int, int); + int gn(int, int); +}; + +template +int K1::fn (int a, int b = 3) // { dg-error "default arguments" } +{ + return a - b; +} + +template +int K1::gn (int a = 1, int b = 3) // { dg-error "default arguments" } +{ + return a - b; +} + +template +class K2 +{ + template + int fn(int, int); + template + int gn(int, int); +}; + +template +template +int K2::fn (int a, int b = 3) // { dg-error "default arguments" } +{ + return a - b; +} + +template +template +int K2::gn (int a = 1, int b = 3) // { dg-error "default arguments" } +{ + return a - b; +} Index: testsuite/g++.dg/tc1/dr217.C =================================================================== --- testsuite/g++.dg/tc1/dr217.C (revision 201977) +++ testsuite/g++.dg/tc1/dr217.C (working copy) @@ -10,5 +10,5 @@ struct S }; template -void S::foo (int = 0) // { dg-error "" "default arguments for parameters of member functions of class templates can be specified in the initial declaration only" { xfail *-*-* } } +void S::foo (int = 0) // { dg-error "" "default arguments for parameters of member functions of class templates can be specified in the initial declaration only" } { } Index: testsuite/g++.old-deja/g++.mike/p1989.C =================================================================== --- testsuite/g++.old-deja/g++.mike/p1989.C (revision 201977) +++ testsuite/g++.old-deja/g++.mike/p1989.C (working copy) @@ -108,7 +108,7 @@ List_DL::prepend(const T& item) template void -List_DL::insert(const T& item, Pix x, bool before = TRUE) +List_DL::insert(const T& item, Pix x, bool before = TRUE) // { dg-error "default arguments" } { link *l = (link *) x;