From d9fac9dd59fa8f8d646c98d21f6c874f11e608b5 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 9 Jul 2013 13:56:43 -0400 Subject: [PATCH] re PR c++/57526 (use of X before deduction of auto error for seemingly good code) PR c++/57526 * semantics.c (lambda_capture_field_type): Build a DECLTYPE_TYPE if the variable type uses 'auto'. From-SVN: r200844 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/semantics.c | 2 +- .../g++.dg/cpp0x/lambda/lambda-auto3.C | 24 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 68c6a09cff9..9770f5b38c7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-07-09 Jason Merrill + PR c++/57526 + * semantics.c (lambda_capture_field_type): Build a DECLTYPE_TYPE + if the variable type uses 'auto'. + PR c++/57437 * typeck.c (check_return_expr): Lambda proxies aren't eligible for nrv or return by move. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e06ac61bb80..fd6c8191191 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9177,7 +9177,7 @@ lambda_capture_field_type (tree expr, bool explicit_init_p) } else type = non_reference (unlowered_expr_type (expr)); - if (!type || WILDCARD_TYPE_P (type)) + if (!type || WILDCARD_TYPE_P (type) || type_uses_auto (type)) { type = cxx_make_type (DECLTYPE_TYPE); DECLTYPE_TYPE_EXPR (type) = expr; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto3.C new file mode 100644 index 00000000000..013ed5264ea --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto3.C @@ -0,0 +1,24 @@ +// PR c++/57526 +// { dg-require-effective-target c++11 } + +template +struct A +{ + void bar( ) { } + + void foo( ) + { + auto* this_ptr = this; + auto lc = [&]( ) + { + this_ptr->bar(); + }; + lc(); + } +}; + +int main() +{ + A a; + a.foo(); +}