From 4b7c558dd0ba4af1796c070a26cdeaf60acbad5e Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 24 Mar 2015 15:38:28 -0400 Subject: [PATCH] re PR c++/65498 (ICE in cxx_eval_call_expression when using __func__ inside dependent context) PR c++/65498 * pt.c (get_mostly_instantiated_function_type): Just return the type of the partially instantiated template in DECL_TI_TEMPLATE. From-SVN: r221641 --- gcc/cp/ChangeLog | 6 ++ gcc/cp/pt.c | 58 +------------------ gcc/testsuite/g++.dg/cpp0x/constexpr-targ2.C | 40 +++++++++++++ .../g++.dg/cpp0x/lambda/lambda-template13.C | 2 +- 4 files changed, 49 insertions(+), 57 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-targ2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9bc6337991b..3f948fd18e1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-03-24 Jason Merrill + + PR c++/65498 + * pt.c (get_mostly_instantiated_function_type): Just return the + type of the partially instantiated template in DECL_TI_TEMPLATE. + 2015-03-20 Marek Polacek PR c++/65398 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ea826211996..c649cad75bd 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 00000000000..285d6c9c130 --- /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 2b1a605acd0..01fe3f66cf4 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" } } -- 2.30.2