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 <azzaro...@gmail.com> PR c++/64948 * lambda.c (add_capture) Do not consider as rvalues all expressions involving template parameters. -- Andrea Azzarone
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); +}