diff mbox

[C++,Patch/RFC] PR 64085

Message ID 54F74F00.2090402@oracle.com
State New
Headers show

Commit Message

Paolo Carlini March 4, 2015, 6:29 p.m. UTC
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.

////////////////////////

Comments

Paolo Carlini April 2, 2015, 3:28 p.m. UTC | #1
Hi,

I guess I can as well ping this - still in my tree, no issues so far...

On 03/04/2015 07:29 PM, Paolo Carlini wrote:
> 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.

     https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00241.html

Thanks,
Paolo.
Jason Merrill April 3, 2015, 12:35 p.m. UTC | #2
OK.

Jason
diff mbox

Patch

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&>());
+}