diff mbox

PATCH for c++/64948

Message ID CAGqc0-oU5V1GNFjDa5A8qi0jdRMGeX3DCuqWBpq7zf3sdP05FA@mail.gmail.com
State New
Headers show

Commit Message

Andrea Azzarone Feb. 13, 2015, 2:51 p.m. UTC
Hi all,

this patch try to fix PR c++/64948 (Lambda reference capture
initialization in template function creates segmentation fault).

2015-2-13 Andrea Azzarone <azzaronea@gmail.com>
  PR c++/64948
  * lambda.c (add_capture) Do not consider as rvalues all expressions
involving template parameters.

Comments

Andrea Azzarone Feb. 19, 2015, 4:16 p.m. UTC | #1
Ping?

2015-02-13 15:51 GMT+01:00 Andrea Azzarone <azzaronea@gmail.com>:
> Hi all,
>
> this patch try to fix PR c++/64948 (Lambda reference capture
> initialization in template function creates segmentation fault).
>
> 2015-2-13 Andrea Azzarone <azzaronea@gmail.com>
>   PR c++/64948
>   * lambda.c (add_capture) Do not consider as rvalues all expressions
> involving template parameters.
>
>
> --
> Andrea Azzarone
diff mbox

Patch

Index: gcc/cp/lambda.c
===================================================================
--- gcc/cp/lambda.c	(revision 220454)
+++ gcc/cp/lambda.c	(working copy)
@@ -506,7 +506,7 @@  add_capture (tree lambda, tree id, tree
       if (by_reference_p)
 	{
 	  type = build_reference_type (type);
-	  if (!real_lvalue_p (initializer))
+	  if (TREE_TYPE (initializer) && !real_lvalue_p (initializer))
 	    error ("cannot capture %qE by reference", initializer);
 	}
       else
Index: gcc/testsuite/g++.dg/cpp1y/lambda-init13.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/lambda-init13.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp1y/lambda-init13.C	(working copy)
@@ -0,0 +1,10 @@ 
+// PR c++/64948
+// { dg-do compile { target c++14 } }
+
+template <class T>
+void foo(T t) {
+  [&i = t.begin()]() {};
+}
+
+int main() {
+}
Index: gcc/testsuite/g++.dg/cpp1y/lambda-init14.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/lambda-init14.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp1y/lambda-init14.C	(working copy)
@@ -0,0 +1,16 @@ 
+// PR c++/64948
+// { dg-do compile { target c++14 } }
+
+template <class T>
+void foo(T t) {
+  [&i = t.begin()]() {};  // { dg-error "invalid initialization" }
+}
+
+struct X {
+  int begin() { return 0; }
+};
+
+int main() {
+  X x;
+  foo(x);
+}