From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78744 invoked by alias); 12 Nov 2015 20:37:14 -0000 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 Received: (qmail 78043 invoked by uid 89); 12 Nov 2015 20:37:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 12 Nov 2015 20:37:13 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id F0B5FF5DDD for ; Thu, 12 Nov 2015 20:37:11 +0000 (UTC) Received: from [10.10.116.19] (ovpn-116-19.rdu2.redhat.com [10.10.116.19]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tACKbBti000980 for ; Thu, 12 Nov 2015 15:37:11 -0500 To: gcc-patches List From: Jason Merrill Subject: C++ PATCH to checking of explicit instantiation namespace Message-ID: <5644F876.6070306@redhat.com> Date: Thu, 12 Nov 2015 20:37:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050302030109060302070004" X-SW-Source: 2015-11/txt/msg01591.txt.bz2 This is a multi-part message in MIME format. --------------050302030109060302070004 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 309 In the testcase, the using-declaration was confusing namespace comparison into thinking that we were instantiating a template from an enclosing namespace. Given using-declarations, we need to wait until we've chosen a template before donig this comparison. Tested x86_64-pc-linux-gnu, applying to trunk. --------------050302030109060302070004 Content-Type: text/x-patch; name="inst-ns.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="inst-ns.patch" Content-length: 1641 commit 43aa655785ca8da40d07e1320f532950fc9a83b5 Author: Jason Merrill Date: Thu Nov 12 11:22:04 2015 -0500 * pt.c (check_explicit_specialization): Check the namespace after we choose a template. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 62659ec..2e3d48b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2800,14 +2800,6 @@ check_explicit_specialization (tree declarator, error ("%qD is not a template function", dname); fns = error_mark_node; } - else - { - tree fn = OVL_CURRENT (fns); - if (!is_associated_namespace (CP_DECL_CONTEXT (decl), - CP_DECL_CONTEXT (fn))) - error ("%qD is not declared in %qD", - decl, current_namespace); - } } declarator = lookup_template_function (fns, NULL_TREE); @@ -2941,6 +2933,14 @@ check_explicit_specialization (tree declarator, return error_mark_node; else { + if (!ctype && !was_template_id + && (specialization || member_specialization + || explicit_instantiation) + && !is_associated_namespace (CP_DECL_CONTEXT (decl), + CP_DECL_CONTEXT (tmpl))) + error ("%qD is not declared in %qD", + tmpl, current_namespace); + tree gen_tmpl = most_general_template (tmpl); if (explicit_instantiation) diff --git a/gcc/testsuite/g++.dg/template/explicit-instantiation4.C b/gcc/testsuite/g++.dg/template/explicit-instantiation4.C new file mode 100644 index 0000000..72417b4 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/explicit-instantiation4.C @@ -0,0 +1,7 @@ +void f(); + +namespace A { + template void f(T) { } + using ::f; + template void f(int); +} --------------050302030109060302070004--