From a3d94329e909d9d14ba6a6cf9f398cdafc84da53 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 3 Apr 2015 17:23:27 +0000 Subject: [PATCH] re PR c++/64085 (ICE on C++14 lambda by-reference capture with an initializer) /cp 2015-04-03 Paolo Carlini PR c++/64085 * lambda.c (add_capture): Use dependent_type_p for capture by reference too. /testsuite 2015-04-03 Paolo Carlini PR c++/64085 * g++.dg/cpp1y/lambda-init13.C: New. From-SVN: r221858 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/lambda.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp1y/lambda-init13.C | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-init13.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ca048aaaefb..b84f3374618 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-04-03 Paolo Carlini + + PR c++/64085 + * lambda.c (add_capture): Use dependent_type_p for capture by + reference too. + 2015-04-02 Marek Polacek PR c++/65642 diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index b160c8cb7ae..dd1c2d4337a 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -506,7 +506,7 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p, if (by_reference_p) { type = build_reference_type (type); - if (!real_lvalue_p (initializer)) + if (!dependent_type_p (type) && !real_lvalue_p (initializer)) error ("cannot capture %qE by reference", initializer); } else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0810c131b40..3e87768625a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-04-03 Paolo Carlini + + PR c++/64085 + * g++.dg/cpp1y/lambda-init13.C: New. + 2015-04-03 Marek Polacek * g++.dg/cpp0x/pr57101.C: Use proper type for size_t. diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init13.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init13.C new file mode 100644 index 00000000000..9b1d139c6d4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init13.C @@ -0,0 +1,18 @@ +// PR c++/64085 +// { dg-do compile { target c++14 } } + +template +struct reference_wrapper +{ + T& get() const noexcept; +}; + +template +auto make_monad(reference_wrapper arg) { + return [&captive = arg.get()](auto&&) { return 1; }; +} + +int main() +{ + make_monad(reference_wrapper()); +} -- 2.30.2