From patchwork Mon Oct 26 21:17:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 536256 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 2C3FA141347 for ; Tue, 27 Oct 2015 08:17:25 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=hTi9NxdY; 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=L566jD9d4p79+EbuQIkG/j6hfQC9XTOLLqMy0U1HW9iVHhH5t9 jGv0TEuflGDX9agIFn/CmGhzRomrz6qaA+BMTmXrk+QU4Td+2otMZVWxX5w4Gbr6 Ep2EElgPpYGMNDFHVCVAsxXLztz8xxSr5tS6zC8IkUQfJHcsdz+CreFeg= 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=aRgcdrOO1JPDTxNrNRDg6vciyhk=; b=hTi9NxdYkDmzjQcnE9Jb h9goOK32PWS/koP7FCeAFjsZdvrgtt/HYr444S2AIMlvLQi2vsmIesqaGTsO3h+M zjylsuIEFI/DZD/e+NN7AxoRbMnF3BvAnylWyY+ikh2wtRBrhuBtYZj3t2CnWZnX LuSYImkzmIQJSpe7WAEeigY= Received: (qmail 107383 invoked by alias); 26 Oct 2015 21:17:18 -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 107370 invoked by uid 89); 26 Oct 2015 21:17:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 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; Mon, 26 Oct 2015 21:17:16 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 6E94CC0B5907 for ; Mon, 26 Oct 2015 21:17:15 +0000 (UTC) Received: from [10.10.116.50] (ovpn-116-50.rdu2.redhat.com [10.10.116.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9QLHEfP008867 for ; Mon, 26 Oct 2015 17:17:15 -0400 To: gcc-patches List From: Jason Merrill Subject: C++ PATCH for DR 2179 (ambiguous partial specialization after instantiation) Message-ID: <562E985A.6060009@redhat.com> Date: Mon, 26 Oct 2015 17:17:14 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 While discussing issue 2179 at the meeting last week, I noticed that we were crashing when a partial specialization made a previous instantiation ambiguous. Fixed thus. Tested x86_64-pc-linux-gnu, applying to trunk. commit cb0817f19d7f4ce9878922412c2c1b2d07eb66d7 Author: Jason Merrill Date: Sun Oct 25 05:22:50 2015 -1000 DR 2179 * pt.c (process_partial_specialization): Handle error_mark_node from most_specialized_partial_spec. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ffe02da..2745b40 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4690,14 +4690,18 @@ process_partial_specialization (tree decl) : DECL_TEMPLATE_INSTANTIATION (instance)) { tree spec = most_specialized_partial_spec (instance, tf_none); - if (spec && TREE_VALUE (spec) == tmpl) - { - tree inst_decl = (DECL_P (instance) - ? instance : TYPE_NAME (instance)); - permerror (input_location, - "partial specialization of %qD after instantiation " - "of %qD", decl, inst_decl); - } + tree inst_decl = (DECL_P (instance) + ? instance : TYPE_NAME (instance)); + if (!spec) + /* OK */; + else if (spec == error_mark_node) + permerror (input_location, + "declaration of %qD ambiguates earlier template " + "instantiation for %qD", decl, inst_decl); + else if (TREE_VALUE (spec) == tmpl) + permerror (input_location, + "partial specialization of %qD after instantiation " + "of %qD", decl, inst_decl); } } diff --git a/gcc/testsuite/g++.dg/template/partial-specialization3.C b/gcc/testsuite/g++.dg/template/partial-specialization3.C new file mode 100644 index 0000000..c5f83bd --- /dev/null +++ b/gcc/testsuite/g++.dg/template/partial-specialization3.C @@ -0,0 +1,7 @@ +// DR 2179 + +template class A; +template struct A { void f(); }; +template void g(T) { A().f(); } // #1 +template struct A {}; // { dg-error "" } +A f; // #2