diff options
author | Jason Merrill <jason@redhat.com> | 2015-09-08 15:33:47 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2015-09-08 15:33:47 -0400 |
commit | 979734578a6c2a11dce55c3c583c051b13b45ffc (patch) | |
tree | 66b0992bdfac4420f7c587efa762b86ef109cddc | |
parent | 51aae43f235863454bcce315c748b2836c5d3f98 (diff) | |
download | gcc-979734578a6c2a11dce55c3c583c051b13b45ffc.zip gcc-979734578a6c2a11dce55c3c583c051b13b45ffc.tar.gz gcc-979734578a6c2a11dce55c3c583c051b13b45ffc.tar.bz2 |
re PR c++/67041 ([C++14] Variable template initialized by call to lambda does not compile)
PR c++/67041
* pt.c (tsubst_copy_and_build): Handle variables like functions.
From-SVN: r227553
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/pt.c | 19 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/lambda-var-templ1.C | 11 |
3 files changed, 27 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6115fd1..3a412ae 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2015-09-08 Jason Merrill <jason@redhat.com> + + PR c++/67041 + * pt.c (tsubst_copy_and_build): Handle variables like functions. + 2015-09-08 Paolo Carlini <paolo.carlini@oracle.com> PR c++/67369 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2544751..05e6d83 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16321,15 +16321,14 @@ tsubst_copy_and_build (tree t, LAMBDA_EXPR_MUTABLE_P (r) = LAMBDA_EXPR_MUTABLE_P (t); LAMBDA_EXPR_DISCRIMINATOR (r) = (LAMBDA_EXPR_DISCRIMINATOR (t)); - /* For a function scope, we want to use tsubst so that we don't - complain about referring to an auto function before its return - type has been deduced. Otherwise, we want to use tsubst_copy so - that we look up the existing field/parameter/variable rather - than build a new one. */ tree scope = LAMBDA_EXPR_EXTRA_SCOPE (t); - if (scope && TREE_CODE (scope) == FUNCTION_DECL) + if (!scope) + /* No substitution needed. */; + else if (VAR_OR_FUNCTION_DECL_P (scope)) + /* For a function or variable scope, we want to use tsubst so that we + don't complain about referring to an auto before deduction. */ scope = tsubst (scope, args, complain, in_decl); - else if (scope && TREE_CODE (scope) == PARM_DECL) + else if (TREE_CODE (scope) == PARM_DECL) { /* Look up the parameter we want directly, as tsubst_copy doesn't do what we need. */ @@ -16342,8 +16341,12 @@ tsubst_copy_and_build (tree t, if (DECL_CONTEXT (scope) == NULL_TREE) DECL_CONTEXT (scope) = fn; } - else + else if (TREE_CODE (scope) == FIELD_DECL) + /* For a field, use tsubst_copy so that we look up the existing field + rather than build a new one. */ scope = RECUR (scope); + else + gcc_unreachable (); LAMBDA_EXPR_EXTRA_SCOPE (r) = scope; LAMBDA_EXPR_RETURN_TYPE (r) = tsubst (LAMBDA_EXPR_RETURN_TYPE (t), args, complain, in_decl); diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-var-templ1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-var-templ1.C new file mode 100644 index 0000000..4c2a3cb --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-var-templ1.C @@ -0,0 +1,11 @@ +// PR c++/67041 +// { dg-do compile { target c++14 } } + +template<typename T> +auto test = [](){ + return T{}; +}; + +int main() { + test<int>(); +} |