From patchwork Tue Jan 25 22:29:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 80416 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 E015FB70EB for ; Wed, 26 Jan 2011 09:30:15 +1100 (EST) Received: (qmail 23547 invoked by alias); 25 Jan 2011 22:30:10 -0000 Received: (qmail 23517 invoked by uid 22791); 25 Jan 2011 22:30:07 -0000 X-SWARE-Spam-Status: No, hits=-5.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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; Tue, 25 Jan 2011 22:29:58 +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.13.8/8.13.8) with ESMTP id p0PMTuhl020834 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 25 Jan 2011 17:29:56 -0500 Received: from adjoa.redhat.com (ovpn-113-80.phx2.redhat.com [10.3.113.80]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p0PMTo72004094; Tue, 25 Jan 2011 17:29:54 -0500 From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: Re: PR c++/47311 References: <4D3A054A.5080306@redhat.com> X-URL: http://www.redhat.com Date: Tue, 25 Jan 2011 23:29:50 +0100 In-Reply-To: <4D3A054A.5080306@redhat.com> (Jason Merrill's message of "Fri, 21 Jan 2011 17:14:34 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes 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 Jason Merrill writes: > On 01/20/2011 10:40 AM, Dodji Seketeli wrote: >> + if (incomplete_args_for_template_parm_fixup_p (arglist, parm)) > > It seems to me that if we do things in the right order, we shouldn't > need this test. Can't we arrange to defer fixing up template template > parameter template parameters some other way than testing what's in > the arglist? The idea of changing the signature of some functions to pass down the information that we are parsing the parameter-list of a template template parameter during stage 3 made me shudder at first. That's why I try that other way. I agree this wasn't rational. The patch below basically adds a flag to cp_parser_template_parameter_list so it knows when it is processing the parameters of a template template parm. It passes the information down to end_template_parm_list that just avoids doing the fixup in that case. The change of fixup_template_parm is to fixup the parms of a template template parameter before fixing its type. Tested on x86_unknown-linux-gnu without boostrap; a full boostrap is currently running. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 7500826..3669578 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5024,7 +5024,7 @@ extern tree splice_late_return_type (tree, tree); extern bool is_auto (const_tree); extern tree process_template_parm (tree, location_t, tree, bool, bool, unsigned); -extern tree end_template_parm_list (tree); +extern tree end_template_parm_list (tree, bool); extern void end_template_decl (void); extern tree maybe_update_decl_type (tree, tree); extern bool check_default_tmpl_args (tree, tree, int, int, int); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 41f82ac..c328639 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -2039,7 +2039,7 @@ static tree cp_parser_operator static void cp_parser_template_declaration (cp_parser *, bool); static tree cp_parser_template_parameter_list - (cp_parser *); + (cp_parser *, bool); static tree cp_parser_template_parameter (cp_parser *, bool *, bool *); static tree cp_parser_type_parameter @@ -11131,7 +11131,8 @@ cp_parser_template_declaration (cp_parser* parser, bool member_p) The nodes are connected via their TREE_CHAINs. */ static tree -cp_parser_template_parameter_list (cp_parser* parser) +cp_parser_template_parameter_list (cp_parser* parser, + bool template_template_parm_p) { tree parameter_list = NULL_TREE; @@ -11176,7 +11177,8 @@ cp_parser_template_parameter_list (cp_parser* parser) cp_lexer_consume_token (parser->lexer); } - return end_template_parm_list (parameter_list); + return end_template_parm_list (parameter_list, + template_template_parm_p); } /* Parse a template-parameter. @@ -11433,7 +11435,7 @@ cp_parser_type_parameter (cp_parser* parser, bool *is_parameter_pack) /* Look for the `<'. */ cp_parser_require (parser, CPP_LESS, RT_LESS); /* Parse the template-parameter-list. */ - cp_parser_template_parameter_list (parser); + cp_parser_template_parameter_list (parser, true); /* Look for the `>'. */ cp_parser_require (parser, CPP_GREATER, RT_GREATER); /* Look for the `class' keyword. */ @@ -19920,7 +19922,7 @@ cp_parser_template_declaration_after_export (cp_parser* parser, bool member_p) } else /* Parse the template parameters. */ - parameter_list = cp_parser_template_parameter_list (parser); + parameter_list = cp_parser_template_parameter_list (parser, false); /* Get the deferred access checks from the parameter list. These will be checked once we know what is being declared, as for a diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7d39e1c..f9b2280 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -3597,7 +3597,8 @@ process_template_parm (tree list, location_t parm_loc, tree parm, as PARM_DECLs. */ tree -end_template_parm_list (tree parms) +end_template_parm_list (tree parms, + bool template_template_parm_p) { int nparms; tree parm, next; @@ -3614,7 +3615,8 @@ end_template_parm_list (tree parms) TREE_CHAIN (parm) = NULL_TREE; } - fixup_template_parms (); + if (!template_template_parm_p) + fixup_template_parms (); --processing_template_parmlist; @@ -3774,21 +3776,16 @@ fixup_template_parm (tree parm_desc, { /* PARM is a template template parameter. This is going to be interesting. */ - tree tparms, targs, innermost_args; + tree tparms, targs, innermost_args, t; int j; - /* First, fix up the type of the parm. */ + /* First, fix up the parms of the template template parm + because the parms are involved in defining the new canonical + type of the template template parm. */ - tree t = - fixup_template_type_parm_type (TREE_TYPE (parm), num_parms); - TREE_TYPE (parm) = t; - - TREE_VEC_ELT (fixedup_args, idx) = - template_parm_to_arg (parm_desc); - - /* Now we need to substitute the template parm types that - have been fixed up so far into the non-type template - parms of this template template parm. E.g, consider this: + /* So we need to substitute the template parm types that have + been fixed up so far into the template parms of this template + template parm. E.g, consider this: template class TT> class S; @@ -3827,6 +3824,14 @@ fixup_template_parm (tree parm_desc, TREE_VEC_LENGTH (tparms), targs); } + + /* Now fix up the type of the template template parm. */ + + t = fixup_template_type_parm_type (TREE_TYPE (parm), num_parms); + TREE_TYPE (parm) = t; + + TREE_VEC_ELT (fixedup_args, idx) = + template_parm_to_arg (parm_desc); } else if (TREE_CODE (parm) == PARM_DECL) { @@ -3882,7 +3887,7 @@ fixup_template_parm (tree parm_desc, pop_deferring_access_checks (); } -/* Walk current the template parms and properly compute the canonical +/* Walk the current template parms and properly compute the canonical types of the dependent types created during cp_parser_template_parameter_list. */ @@ -3911,8 +3916,6 @@ fixup_template_parms (void) arglist = current_template_args (); arglist = add_outermost_template_args (arglist, fixedup_args); - fixedup_args = INNERMOST_TEMPLATE_ARGS (arglist); - /* Let's do the proper fixup now. */ for (i = 0; i < num_parms; ++i) fixup_template_parm (TREE_VEC_ELT (parameter_vec, i), diff --git a/gcc/testsuite/g++.dg/template/param2.C b/gcc/testsuite/g++.dg/template/param2.C new file mode 100644 index 0000000..d25b855 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/param2.C @@ -0,0 +1,8 @@ +// Origin PR c++/47311 +// { dg-do compile } + +template < typename > class A0; +template class TC = A0> class B0; + +template class A1; +template class TC = A1> class B1;