From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90273 invoked by alias); 24 Mar 2015 19:37:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 90253 invoked by uid 89); 24 Mar 2015 19:37:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_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, 24 Mar 2015 19:37:12 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 37B59B5944 for ; Tue, 24 Mar 2015 19:37:11 +0000 (UTC) Received: from [10.10.116.34] ([10.10.116.34]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2OJb8jV012621 for ; Tue, 24 Mar 2015 15:37:09 -0400 Message-ID: <5511BCE3.2090304@redhat.com> Date: Tue, 24 Mar 2015 19:37:00 -0000 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/65498 (ICE with constexpr template argument) Content-Type: multipart/mixed; boundary="------------010300050108030809040401" X-SW-Source: 2015-03/txt/msg01263.txt.bz2 This is a multi-part message in MIME format. --------------010300050108030809040401 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 615 This testcase was breaking because is_same::operator() is only used in constexpr evaluation, so cgraph decides it isn't used and throws it away. Then mangling tries to use it for constexpr evaluation while re-instantiating F under get_mostly_instantiated_function_type, and sadness ensues. It occurred to me that we really ought to be able to avoid re-doing this instantiation, since DECL_TI_TEMPLATE of a function is a partially instantiated template that already has the type we want. And indeed this seems to work well, even fixing a bug in mangling. Tested x86_64-pc-linux-gnu, applying to trunk. --------------010300050108030809040401 Content-Type: text/x-patch; name="65498.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="65498.patch" Content-length: 4163 commit 11b13941b2b09f20cb0d42a48199b17a927f624f Author: Jason Merrill Date: Mon Mar 23 18:44:04 2015 -0400 PR c++/65498 * pt.c (get_mostly_instantiated_function_type): Just return the type of the partially instantiated template in DECL_TI_TEMPLATE. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ea82621..c649cad 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -20748,62 +20748,8 @@ tsubst_enum (tree tag, tree newtag, tree args) tree get_mostly_instantiated_function_type (tree decl) { - tree fn_type; - tree tmpl; - tree targs; - tree tparms; - int parm_depth; - - tmpl = most_general_template (DECL_TI_TEMPLATE (decl)); - targs = DECL_TI_ARGS (decl); - tparms = DECL_TEMPLATE_PARMS (tmpl); - parm_depth = TMPL_PARMS_DEPTH (tparms); - - /* There should be as many levels of arguments as there are levels - of parameters. */ - gcc_assert (parm_depth == TMPL_ARGS_DEPTH (targs)); - - fn_type = TREE_TYPE (tmpl); - - if (parm_depth == 1) - /* No substitution is necessary. */ - ; - else - { - int i; - tree partial_args; - - /* Replace the innermost level of the TARGS with NULL_TREEs to - let tsubst know not to substitute for those parameters. */ - partial_args = make_tree_vec (TREE_VEC_LENGTH (targs)); - for (i = 1; i < TMPL_ARGS_DEPTH (targs); ++i) - SET_TMPL_ARGS_LEVEL (partial_args, i, - TMPL_ARGS_LEVEL (targs, i)); - SET_TMPL_ARGS_LEVEL (partial_args, - TMPL_ARGS_DEPTH (targs), - make_tree_vec (DECL_NTPARMS (tmpl))); - - /* Make sure that we can see identifiers, and compute access - correctly. */ - push_access_scope (decl); - - ++processing_template_decl; - /* Now, do the (partial) substitution to figure out the - appropriate function type. */ - fn_type = tsubst (fn_type, partial_args, tf_error, NULL_TREE); - --processing_template_decl; - - /* Substitute into the template parameters to obtain the real - innermost set of parameters. This step is important if the - innermost set of template parameters contains value - parameters whose types depend on outer template parameters. */ - TREE_VEC_LENGTH (partial_args)--; - tparms = tsubst_template_parms (tparms, partial_args, tf_error); - - pop_access_scope (decl); - } - - return fn_type; + /* For a function, DECL_TI_TEMPLATE is partially instantiated. */ + return TREE_TYPE (DECL_TI_TEMPLATE (decl)); } /* Return truthvalue if we're processing a template different from diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-targ2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-targ2.C new file mode 100644 index 0000000..285d6c9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-targ2.C @@ -0,0 +1,40 @@ +// PR c++/65498 +// { dg-do compile { target c++11 } } + +template +struct is_same +{ + enum { value = false }; + constexpr bool operator()() const noexcept { return value; } +}; + +template +struct is_same +{ + enum { value = true }; + constexpr bool operator()() const noexcept { return value; } +}; + +template +struct enable_if { }; + +template +struct enable_if { typedef T type; }; + +struct A; + +template +struct F { }; + +template +struct F{}()>::type> { + template + F(MakeDependent) { + auto ICE_HERE = __func__; + (void)ICE_HERE; // avoid -Wunused-variable + } +}; + +int main() { + F{1}; +} diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C index 2b1a605..01fe3f6 100644 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C @@ -20,5 +20,5 @@ void bar () c.foo (1); } -// { dg-final { scan-assembler "_ZN8functionC1IZN1CIiE3fooIiEEvT_S_Ed_UlvE_EET_" } } +// { dg-final { scan-assembler "_ZN8functionC1IZN1CIiE3fooIiEEvT_S_Ed_UlvE_EES4_" } } // { dg-final { scan-assembler-not "_ZZN1CIiE3fooIiEEvT_8functionEd_NKUlvE_clEv" } } --------------010300050108030809040401--