Hi,
today while working a bit on Bugzilla I found this issue which should be
easy to fix, not a regression, therefore possibly post 5.0. At parsing
time, cp_parser_lambda_introducer ends up calling real_lvalue_p on the
lambda initializer (via add_capture), but then the initializer, which is
a CALL_EXPR, crashes immediately lvalue_kind because its TREE_TYPE is
not set (we are dealing with a template function). I guess that, in this
case too, we want to check first dependent_type_p. Tested x86_64-linux.
Thanks,
Paolo.
////////////////////////
Index: cp/lambda.c
===================================================================
--- cp/lambda.c (revision 221180)
+++ cp/lambda.c (working copy)
@@ -506,7 +506,7 @@ add_capture (tree lambda, tree id, tree orig_init,
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
Index: testsuite/g++.dg/cpp1y/lambda-init13.C
===================================================================
--- testsuite/g++.dg/cpp1y/lambda-init13.C (revision 0)
+++ testsuite/g++.dg/cpp1y/lambda-init13.C (working copy)
@@ -0,0 +1,18 @@
+// PR c++/64085
+// { dg-do compile { target c++14 } }
+
+template<typename T>
+struct reference_wrapper
+{
+ T& get() const noexcept;
+};
+
+template<class T>
+auto make_monad(reference_wrapper<T> arg) {
+ return [&captive = arg.get()](auto&&) { return 1; };
+}
+
+int main()
+{
+ make_monad(reference_wrapper<int&>());
+}