From patchwork Sun Sep 1 17:02:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 271631 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 C13C82C0098 for ; Mon, 2 Sep 2013 03:02:30 +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=G/FN/1HpIZ6HGZ2f/i7SCZyv9a+q/uis/Pe/PgEvqB5 Zn1aVlnrtpCTG3aldNC3rbP7irtuldAirCIsIIrDfDfi7yn6rcsbcBG+JRFkt6uo dYS0hG6McKOJbMuzhCkSVX7PyNt1RNx0m8/2YZtVV1AqYeFaEONTg79FNhVDCo58 = 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=Z40gp/G2rxuXjKRLXXZpRYvEcUk=; b=pPhhXpznbu2aH4ZWE KXIUHGSwgUMW8QX68LEe3IIl72HfCFRLUtS4gb2zPgjBmqKjdCFzU2RU6gbDkNk4 uQnqWba37YEet+t4Vcb92SmfKeYNzSxKlGFHuHPDGMlkY/h9PSmIKKt6/DXTPvgC o91HkfXpNT+WMiV9j0JK7+xHZ0= Received: (qmail 2165 invoked by alias); 1 Sep 2013 17:02:24 -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 2153 invoked by uid 89); 1 Sep 2013 17:02:23 -0000 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-SHA encrypted) ESMTPS; Sun, 01 Sep 2013 17:02:23 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-7.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.2 X-HELO: aserp1040.oracle.com Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r81H2JBb019049 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 1 Sep 2013 17:02:20 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r81H2INc004762 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 1 Sep 2013 17:02:19 GMT Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r81H2I03008583; Sun, 1 Sep 2013 17:02:18 GMT Received: from poldo4.casa (/79.52.195.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 01 Sep 2013 10:02:17 -0700 Message-ID: <52237317.60400@oracle.com> Date: Sun, 01 Sep 2013 19:02:15 +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 21682 (DR 565) X-IsSubscribed: yes Hi, this patch resolves the bug by implementing the resolution of DR 565 (DRWP): for template functions, in order to establish that the program is ill-formed we want to check return type and template parameter list too. Thus, in practice, we want to accept the reduced testcase which came with c++/21682 (using24.C) and reject the testcase which I discussed in DR 565 (using25.C) (*) Booted & tested x86_64-linux. Thanks! Paolo. (*) Likewise current clang. ////////////////////////// /cp 2013-09-01 Paolo Carlini PR c++/21682, implement DR 565 * name-lookup.c (do_nonmember_using_decl): For template function, check return type and template parameter list too. /testsuite 2013-09-01 Paolo Carlini PR c++/21682, implement DR 565 * g++.dg/template/using24.C: New. * g++.dg/template/using25.C: Likewise. Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 202141) +++ cp/name-lookup.c (working copy) @@ -2562,7 +2562,20 @@ do_nonmember_using_decl (tree scope, tree name, tr else if (TREE_CODE (tmp1) == OVERLOAD && OVL_USED (tmp1)) continue; /* this is a using decl */ else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)), - TYPE_ARG_TYPES (TREE_TYPE (old_fn)))) + TYPE_ARG_TYPES (TREE_TYPE (old_fn))) + /* DR 565: If a function template declaration in + namespace scope has the same name, parameter- + type-list, return type, and template parameter + list as a function template introduced by a + using-declaration, the program is ill-formed. */ + && (TREE_CODE (new_fn) != TEMPLATE_DECL + || TREE_CODE (old_fn) != TEMPLATE_DECL + || (comp_template_parms + (DECL_TEMPLATE_PARMS (new_fn), + DECL_TEMPLATE_PARMS (old_fn)) + && (same_type_p + (TREE_TYPE (TREE_TYPE (new_fn)), + TREE_TYPE (TREE_TYPE (old_fn))))))) { gcc_assert (!DECL_ANTICIPATED (old_fn) || DECL_HIDDEN_FRIEND_P (old_fn)); Index: testsuite/g++.dg/template/using24.C =================================================================== --- testsuite/g++.dg/template/using24.C (revision 0) +++ testsuite/g++.dg/template/using24.C (working copy) @@ -0,0 +1,30 @@ +// PR c++/21682 + +template +struct t +{ + typedef typename T::type type; +}; +template<> class t{}; + +template struct t1{ }; +template<> struct t1 +{ + typedef int type; +}; + +namespace name1 +{ + template typename t::type begin(S const& s); + namespace name2 + { + template typename t1::type begin(S const& s); + } + using name2::begin; +} + +/* Test calling the function. */ +int f(int a) { return name1::begin(a); } + +struct aa { typedef double type; }; +double g(aa t) { return name1::begin(t); } Index: testsuite/g++.dg/template/using25.C =================================================================== --- testsuite/g++.dg/template/using25.C (revision 0) +++ testsuite/g++.dg/template/using25.C (working copy) @@ -0,0 +1,9 @@ +// PR c++/21682 + +namespace one { + template void fun(T); +} + +using one::fun; + +template void fun(T); // { dg-error "conflicts" }