From patchwork Thu Dec 6 14:26:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 204242 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]) by ozlabs.org (Postfix) with SMTP id 1D3DF2C0287 for ; Fri, 7 Dec 2012 01:26:45 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1355408806; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=kxKvNhq kDbnzPSOUy6N1yEC5Wew=; b=SyHdRTsRP5HOhypSvVnaVWyTSFZDYTawyOHb+ie lXKLFKNh4TxoRVTU/eAOGQHKQTQpUWLxB5BsYVxg1fWV2jW8W5NNgwXlB9elOkXi +zgaQH3YRNH2I71QcD+sz2dazeeQZGYZ+9bhQPqKz3Ib400WYzElHy0A1dV7Cpm8 VweM= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=itfxSVlCAciEFs+9hAdef9exuUFfMoV8Y2FrSFnJ802XzjCPNuWnESdkAvW3Mr xZGGMDkRfYViss+d2WxPh/QA2w5EEibGxRSxQPzErG2peRZddT6TwrjamG/0+ZTy iFIsFXWSypjDuMhPR9ZReNyERMVexL4OkR1259orwHRWQ=; Received: (qmail 22011 invoked by alias); 6 Dec 2012 14:26:42 -0000 Received: (qmail 22003 invoked by uid 22791); 6 Dec 2012 14:26:41 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 06 Dec 2012 14:26:32 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qB6EQW0D012592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Dec 2012 09:26:32 -0500 Received: from [10.3.113.18] ([10.3.113.18]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qB6EQVOO025035 for ; Thu, 6 Dec 2012 09:26:31 -0500 Message-ID: <50C0AB17.6010808@redhat.com> Date: Thu, 06 Dec 2012 09:26:31 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/54653 (ICE with missing template-header) 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 In this PR, we have a partial specialization of a member of a partial specialization, and we were confused into thinking that we only needed one template-header. The parser.c hunk makes us generate the appropriate error. The pt.c hunks fix the compiler to deal with it properly if it had been valid, since I expect we will allow explicit specialization of members of templates in the future. Tested x86_64-pc-linux-gnu, applying to trunk. commit 1633b5ae07f673a578393fae691d7c4f3f7bf9bb Author: Jason Merrill Date: Wed Dec 5 16:24:26 2012 -0500 PR c++/54653 * parser.c (cp_parser_class_head): A partial specialization scope counts as a template. * pt.c (tsubst_template_parms): Handle template template parm parms. (tsubst_decl) [TEMPLATE_DECL]: Handle getting a template template argument back. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 1fe6246..190b8d9 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -18589,7 +18589,8 @@ cp_parser_class_head (cp_parser* parser, && CLASS_TYPE_P (scope) && CLASSTYPE_TEMPLATE_INFO (scope) && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (scope)) - && !CLASSTYPE_TEMPLATE_SPECIALIZATION (scope)) + && (!CLASSTYPE_TEMPLATE_SPECIALIZATION (scope) + || uses_template_parms (CLASSTYPE_TI_ARGS (scope)))) ++num_templates; } } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 27084a2..c1e12f0 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9552,7 +9552,7 @@ tsubst_template_parms (tree parms, tree args, tsubst_flags_t complain) ++processing_template_decl; for (new_parms = &r; - TMPL_PARMS_DEPTH (parms) > TMPL_ARGS_DEPTH (args); + parms && TMPL_PARMS_DEPTH (parms) > TMPL_ARGS_DEPTH (args); new_parms = &(TREE_CHAIN (*new_parms)), parms = TREE_CHAIN (parms)) { @@ -9831,6 +9831,10 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl); if (new_type == error_mark_node) RETURN (error_mark_node); + /* If we get a real template back, return it. This can happen in + the context of most_specialized_class. */ + if (TREE_CODE (new_type) == TEMPLATE_DECL) + return new_type; r = copy_decl (t); DECL_CHAIN (r) = NULL_TREE; diff --git a/gcc/testsuite/g++.dg/template/partial-specialization2.C b/gcc/testsuite/g++.dg/template/partial-specialization2.C new file mode 100644 index 0000000..c22d739 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/partial-specialization2.C @@ -0,0 +1,8 @@ +// PR c++/54653 + +template struct A; +template struct A { + template struct B; +}; + +template struct A::B { }; // { dg-error "too few template-parameter-lists" }