From: Jason Merrill Date: Tue, 9 Jul 2013 17:50:57 +0000 (-0400) Subject: re PR c++/57437 (C++11: mutable lambdas) X-Git-Tag: releases/gcc-4.7.4~584 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbf86c8c2020f21007ef1d43b2159238df2eea28;p=thirdparty%2Fgcc.git re PR c++/57437 (C++11: mutable lambdas) PR c++/57437 * typeck.c (check_return_expr): Lambda proxies aren't eligible for nrv or return by move. From-SVN: r200832 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a9abf59eb707..b0e6133b9f78 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-07-09 Jason Merrill + PR c++/57437 + * typeck.c (check_return_expr): Lambda proxies aren't eligible + for nrv or return by move. + PR c++/57545 * pt.c (convert_nontype_argument) [INTEGER_CST]: Force the argument to have the exact type of the parameter. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index c404c81c5e3c..796eea6465cb 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -7929,7 +7929,8 @@ check_return_expr (tree retval, bool *no_warning) && TREE_CODE (retval) == VAR_DECL && DECL_CONTEXT (retval) == current_function_decl && ! TREE_STATIC (retval) - && ! DECL_ANON_UNION_VAR_P (retval) + /* And not a lambda or anonymous union proxy. */ + && !DECL_HAS_VALUE_EXPR_P (retval) && (DECL_ALIGN (retval) >= DECL_ALIGN (DECL_RESULT (current_function_decl))) /* The cv-unqualified type of the returned value must be the @@ -7978,7 +7979,8 @@ check_return_expr (tree retval, bool *no_warning) Note that these conditions are similar to, but not as strict as, the conditions for the named return value optimization. */ if ((cxx_dialect != cxx98) - && (TREE_CODE (retval) == VAR_DECL + && ((TREE_CODE (retval) == VAR_DECL + && !DECL_HAS_VALUE_EXPR_P (retval)) || TREE_CODE (retval) == PARM_DECL) && DECL_CONTEXT (retval) == current_function_decl && !TREE_STATIC (retval) diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C new file mode 100644 index 000000000000..4b353b64c37e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C @@ -0,0 +1,26 @@ +// PR c++/57437 +// { dg-require-effective-target c++11 } + +struct A { + int i; + + A(): i(42) {} + A(const A&) = default; + A(A&& a): i(a.i) { a.i = 0; } +}; + +int main() +{ + A x; + + auto y = [x] () mutable { + x.i++; + return x; + }; + + if (y().i != 43) + __builtin_abort (); + + if (y().i != 44) + __builtin_abort (); +}