From patchwork Thu Nov 12 20:37:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 543648 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 2F399140134 for ; Fri, 13 Nov 2015 07:37:22 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=SESgwJAM; 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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=YvrIh6izEynK84htmHXa7O2kZlpbZvO+5nRgXwvp/S18aa5cnX zujjPSE9XRK5ewfWFlrE1pwEdnsU9gLfuwVn3qawGyMrrKJYUvimeTCoAKpty9hA 0g3zOVVEQz9CePCHdVHq2KaB70j4OiFyLQpOr1fhs3WPc69j8whBULeRQ= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=C1v9YwRLm5Avhx98DI1Is1lwIMM=; b=SESgwJAM+17KNXQLWb85 hLYPW+wKL2Y6VYGPegta+JPSrbvViH1NobPBAgLXR9dRFCAzhZpADQqUEegtKCvi 99Xq/VNPCPZboPfbS6drq6VRUYs/NGG+KRjCi8rv25dEBNCSwLb8RnMNhbP5sAFW n56Bwjkfb6jdnBIiEApU7VA= 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-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 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 15:37:10 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 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. 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); +}