From patchwork Fri Jan 11 10:38:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 211294 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 256762C01E6 for ; Fri, 11 Jan 2013 21:38:50 +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=1358505531; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:References:Date:In-Reply-To: Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=fJExyalPmS0u6aHl6Y3XjbGy+uM=; b=Ap4Jgc5/Gn913iZr+7qCDhewFihILjdlpGtixrPAh47xBLxGl8t+N85XJGj6jC 4YulrcL5UxkEnjwL+JSe8h4nybFu1+ks/ptul+asdzSV/5PbJuV8/h0UkLCXukL+ ah9ixX68/fsfrZrMThGSSLDdXuEYRLUUBoN0fAxCigVQE= 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:Received:From:To:Cc:Subject:References:X-URL:Date:In-Reply-To:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=cuWLaJsuPnHQdJe1ehHr2GhTT5Z1MYC9polfzCizXHTZxpvH2gCo/dW+7NX4ua Zurcd95T5sRt+RG7xyP1klvo9wCWs1FBgKn/TJx30TJWW33PiAAiBRZUV5Ly4w4V XVgsIyMsHEq42GJOCRbxI+V1dA2MOP7pll4OqvKAbsbIU=; Received: (qmail 4141 invoked by alias); 11 Jan 2013 10:38:42 -0000 Received: (qmail 4101 invoked by uid 22791); 11 Jan 2013 10:38:41 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, 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; Fri, 11 Jan 2013 10:38:33 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0BAcX9W031142 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 11 Jan 2013 05:38:33 -0500 Received: from localhost (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0BAcVZZ024304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 11 Jan 2013 05:38:32 -0500 Received: by localhost (Postfix, from userid 1000) id 84A819F1A4; Fri, 11 Jan 2013 11:38:30 +0100 (CET) From: Dodji Seketeli To: Gabriel Dos Reis Cc: GCC Patches , Jason Merrill Subject: Re: [PATCH] PR c++/55663 - constexpr function templ instantiation considered non-const as alias templ arg References: <877gnnwzdg.fsf@redhat.com> <87hamqtlum.fsf@redhat.com> <87k3rlrrkw.fsf@redhat.com> X-URL: http://www.redhat.com Date: Fri, 11 Jan 2013 11:38:30 +0100 In-Reply-To: (Gabriel Dos Reis's message of "Thu, 10 Jan 2013 10:11:43 -0600") Message-ID: <87fw28ovh5.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) MIME-Version: 1.0 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 Gabriel Dos Reis writes: > On Thu, Jan 10, 2013 at 9:22 AM, Dodji Seketeli wrote: > >> But during the instantiation of the *members* of test, we try to >> instantiate Alias>, without coercing (and thus without >> folding) the argument {the_truth}. We do this using >> instantiate_alias_template, called from tsubst. >> >> The patch below makes sure instantiate_alias_template coerces the >> arguments it uses to instantiate the alias template, like what I >> understood you are suggesting. I have tested it without boostrap and a >> full boostrap is currently running. > > Hmm, is it necessary to coerce all levels as opposed to just the > innermost arguments? > > -- Gaby Jason Merrill writes: > On 01/10/2013 11:11 AM, Gabriel Dos Reis wrote: >> Hmm, is it necessary to coerce all levels as opposed to just the >> innermost arguments? > > No. But if you read the code, it's really only coercing the innermost > level. Correct. I even documented that in the descriptive comment of the function. But ... > Just the name is misleading. ... as the name seems to be confusing, I have changed it to coerce_innermost_template_parms. I hope that is less confusing. >> If this approach looks acceptable, could I replace (part of) the >> template argument coercing code in lookup_class_template_1 with the new >> coerce_template_parms_all_level I introduced in this patch? > > Yes. OK. I have done that in the patch below that passed bootstrap and regression testing on x86_64-unknown-linux-gnu against trunk. If nothing else, I'd need your opinion on this; in the template argument coercing code in lookup_template_1 does this: /* We temporarily reduce the length of the ARGLIST so that coerce_template_parms will see only the arguments corresponding to the template parameters it is examining. */ TREE_VEC_LENGTH (arglist)--; but when I read the code, it looks like this is not necessary. Am I missing something? In any case, I haven't put that code in the new coerce_innermost_template_parms. Is that OK? Thanks. gcc/cp/ PR c++/55663 * pt.c (coerce_innermost_template_parms): New static function. (instantiate_alias_template): Use it here. (lookup_template_class_1): Use it here too, for ease of maintenance's sake. gcc/testsuite/ PR c++/55663 * g++.dg/cpp0x/alias-decl-31.C: New test. --- gcc/cp/pt.c | 130 ++++++++++++++++------------- gcc/testsuite/g++.dg/cpp0x/alias-decl-31.C | 20 +++++ 2 files changed, 93 insertions(+), 57 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-31.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 30bafa0..67e6c97 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -130,6 +130,8 @@ static tree tsubst_initializer_list (tree, tree); static tree get_class_bindings (tree, tree, tree, tree); static tree coerce_template_parms (tree, tree, tree, tsubst_flags_t, bool, bool); +static tree coerce_innermost_template_parms (tree, tree, tree, tsubst_flags_t, + bool, bool); static void tsubst_enum (tree, tree, tree); static tree add_to_template_args (tree, tree); static tree add_outermost_template_args (tree, tree); @@ -6742,6 +6744,61 @@ coerce_template_parms (tree parms, return new_inner_args; } +/* Like coerce_template_parms. If PARMS represents all template + parameters levels, this function returns a vector of vectors + representing all the resulting argument levels. Note that in this + case, only the innermost arguments are coerced because the + outermost ones are supposed to have been coerced already. + + Otherwise, if PARMS represents only (the innermost) vector of + parameters, this function returns a vector containing just the + innermost resulting arguments. */ + +static tree +coerce_innermost_template_parms (tree parms, + tree args, + tree in_decl, + tsubst_flags_t complain, + bool require_all_args, + bool use_default_args) +{ + int parms_depth = TMPL_PARMS_DEPTH (parms); + int args_depth = TMPL_ARGS_DEPTH (args); + tree coerced_args; + + if (parms_depth > 1) + { + coerced_args = make_tree_vec (parms_depth); + tree level; + int cur_depth; + + for (level = parms, cur_depth = parms_depth; + parms_depth > 0 && level != NULL_TREE; + level = TREE_CHAIN (level), --cur_depth) + { + tree l; + if (cur_depth == args_depth) + l = coerce_template_parms (TREE_VALUE (level), + args, in_decl, complain, + require_all_args, + use_default_args); + else + l = TMPL_ARGS_LEVEL (args, cur_depth); + + if (l == error_mark_node) + return error_mark_node; + + SET_TMPL_ARGS_LEVEL (coerced_args, cur_depth, l); + } + } + else + coerced_args = coerce_template_parms (INNERMOST_TEMPLATE_PARMS (parms), + args, in_decl, complain, + require_all_args, + use_default_args); + return coerced_args; +} + /* Returns 1 if template args OT and NT are equivalent. */ static int @@ -7169,63 +7226,14 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context, /* From here on, we're only interested in the most general template. */ - /* Calculate the BOUND_ARGS. These will be the args that are - actually tsubst'd into the definition to create the - instantiation. */ - if (parm_depth > 1) - { - /* We have multiple levels of arguments to coerce, at once. */ - int i; - int saved_depth = TMPL_ARGS_DEPTH (arglist); - - tree bound_args = make_tree_vec (parm_depth); - - for (i = saved_depth, - t = DECL_TEMPLATE_PARMS (gen_tmpl); - i > 0 && t != NULL_TREE; - --i, t = TREE_CHAIN (t)) - { - tree a; - if (i == saved_depth) - a = coerce_template_parms (TREE_VALUE (t), - arglist, gen_tmpl, - complain, - /*require_all_args=*/true, - /*use_default_args=*/true); - else - /* Outer levels should have already been coerced. */ - a = TMPL_ARGS_LEVEL (arglist, i); - - /* Don't process further if one of the levels fails. */ - if (a == error_mark_node) - { - /* Restore the ARGLIST to its full size. */ - TREE_VEC_LENGTH (arglist) = saved_depth; - return error_mark_node; - } - - SET_TMPL_ARGS_LEVEL (bound_args, i, a); - - /* We temporarily reduce the length of the ARGLIST so - that coerce_template_parms will see only the arguments - corresponding to the template parameters it is - examining. */ - TREE_VEC_LENGTH (arglist)--; - } - - /* Restore the ARGLIST to its full size. */ - TREE_VEC_LENGTH (arglist) = saved_depth; - - arglist = bound_args; - } - else - arglist - = coerce_template_parms (INNERMOST_TEMPLATE_PARMS (parmlist), - INNERMOST_TEMPLATE_ARGS (arglist), - gen_tmpl, - complain, - /*require_all_args=*/true, - /*use_default_args=*/true); + /* Convert the innermost template arguments to their appropriate + types. These will be the arguments that are actually + tsubst'd into the definition to create the instantiation. */ + arglist = + coerce_innermost_template_parms (parmlist, arglist, + gen_tmpl, complain, + /*require_all_args=*/true, + /*use_default_args=*/true); if (arglist == error_mark_node) /* We were unable to bind the arguments. */ @@ -14637,7 +14645,15 @@ instantiate_alias_template (tree tmpl, tree args, tsubst_flags_t complain) ggc_free (tinst); return error_mark_node; } + + args = + coerce_innermost_template_parms (DECL_TEMPLATE_PARMS (tmpl), + args, tmpl, complain, + /*require_all_args=*/true, + /*use_default_args=*/true); + tree r = instantiate_template (tmpl, args, complain); + pop_tinst_level (); /* We can't free this if a pending_template entry or last_error_tinst_level is pointing at it. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-31.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-31.C new file mode 100644 index 0000000..83eea47 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-31.C @@ -0,0 +1,20 @@ +// Origin: PR c++/55663 +// { dg-do compile { target c++11 } } + +template +constexpr bool the_truth () { return true; } + +template + struct Takes_bool { }; + +template + using Alias = Takes_bool; + +template + struct test { using type = Alias()>; }; + +int main () { + test a; + + return 0; +}