From patchwork Tue Jan 27 19:16:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 433603 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 0A34614016A for ; Wed, 28 Jan 2015 06:17:20 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=xRc4YXivG4wznVPQTMxcqJ0VuZuztxe4pkQH1WAyxQeKxz mdk41asdikd84g2WxezK25EEe0M578KIc3iiSPtEqLhuYG8ZzdDsFFpaHFYa3dvF hXqPLOMdlWbVNgCPaooZzgiQx9ZYJJ37JN3Yx9U7EbgnOerKEuAczq397+65s= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=o1pc2+7UkwhkHu+EUucWza0AgAo=; b=ng93y4B/Y9GuyiyHXYwj DZVJe/gG2ioBhNUp2xVwiD8cl+b8ICLcluk6W2UxFiEEdEKMHlneepoUIPAo4bWB fkjnNyoOiH2GQnCDuw03DnUKW2h/NGzbmuxtoDAES7IzmvMhgXkKtBcRz/HfLsVk KO7noyWOvxDWlBeo83aLQ1Q= Received: (qmail 26414 invoked by alias); 27 Jan 2015 19:16:29 -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 26380 invoked by uid 89); 27 Jan 2015 19:16:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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; Tue, 27 Jan 2015 19:16:26 +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 (8.14.4/8.14.4) with ESMTP id t0RJGOpT025910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 27 Jan 2015 14:16:24 -0500 Received: from [10.10.116.40] ([10.10.116.40]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0RJGN9I016845 for ; Tue, 27 Jan 2015 14:16:24 -0500 Message-ID: <54C7E404.8040602@redhat.com> Date: Tue, 27 Jan 2015 14:16:20 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/63889 (ICE with member variable template) We were trying to instantiate is_ok with only the innermost set of template arguments; we need to make sure that the outer args are provided as well. Tested x86_64-pc-linux-gnu, applying to trunk. commit e2df55ffbe254dfc15801a204af16d012aeb4cb5 Author: Jason Merrill Date: Mon Jan 26 10:55:42 2015 -0500 PR c++/63889 * pt.c (finish_template_variable): Move from semantics.c. Handle multiple template arg levels. Handle coercion here. (lookup_template_variable): Not here. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index bc26530..d377daa 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8091,13 +8091,28 @@ tree lookup_template_variable (tree templ, tree arglist) { tree type = unknown_type_node; - tsubst_flags_t complain = tf_warning_or_error; - tree parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (templ)); - arglist = coerce_template_parms (parms, arglist, templ, complain, - /*req_all*/true, /*use_default*/true); return build2 (TEMPLATE_ID_EXPR, type, templ, arglist); } +/* Instantiate a variable declaration from a TEMPLATE_ID_EXPR for use. */ + +tree +finish_template_variable (tree var) +{ + tree templ = TREE_OPERAND (var, 0); + + tree arglist = TREE_OPERAND (var, 1); + tree tmpl_args = DECL_TI_ARGS (DECL_TEMPLATE_RESULT (templ)); + arglist = add_outermost_template_args (tmpl_args, arglist); + + tree parms = DECL_TEMPLATE_PARMS (templ); + tsubst_flags_t complain = tf_warning_or_error; + arglist = coerce_innermost_template_parms (parms, arglist, templ, complain, + /*req_all*/true, + /*use_default*/true); + + return instantiate_template (templ, arglist, complain); +} struct pair_fn_data { diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 915048d..75aa501 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2454,15 +2454,6 @@ finish_call_expr (tree fn, vec **args, bool disallow_virtual, return result; } -/* Instantiate a variable declaration from a TEMPLATE_ID_EXPR for use. */ - -tree -finish_template_variable (tree var) -{ - return instantiate_template (TREE_OPERAND (var, 0), TREE_OPERAND (var, 1), - tf_error); -} - /* Finish a call to a postfix increment or decrement or EXPR. (Which is indicated by CODE, which should be POSTINCREMENT_EXPR or POSTDECREMENT_EXPR.) */ diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ22.C b/gcc/testsuite/g++.dg/cpp1y/var-templ22.C new file mode 100644 index 0000000..9ddc925 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ22.C @@ -0,0 +1,14 @@ +// PR c++/63889 +// { dg-do compile { target c++14 } } + +template +struct A +{ + template + static constexpr bool is_ok = true; + + template> + A(T) { } +}; + +A p(42);