An earlier patch of mine changed lambda_capture_field_type to avoid
building a DECLTYPE_TYPE in cases where it isn't really necessary, but
it is necessary in the case of capture of an auto variable.
Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
commit 7d406a5c27c48d1d8fe3b182af72e656c8c6bcb3
Author: Jason Merrill <ja...@redhat.com>
Date: Tue Jul 9 02:59:52 2013 -0400
PR c++/57526
* semantics.c (lambda_capture_field_type): Build a DECLTYPE_TYPE
if the variable type uses 'auto'.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 9e49060..b5bcb00 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -9171,7 +9171,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 0000000..013ed52
--- /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<class T>
+struct A
+{
+ void bar( ) { }
+
+ void foo( )
+ {
+ auto* this_ptr = this;
+ auto lc = [&]( )
+ {
+ this_ptr->bar();
+ };
+ lc();
+ }
+};
+
+int main()
+{
+ A<int> a;
+ a.foo();
+}
commit 80bb7027cca5a7c0db92fb0338ae55cb44e9b3d6
Author: Jason Merrill <ja...@redhat.com>
Date: Tue Jul 9 02:59:52 2013 -0400
PR c++/57526
* semantics.c (lambda_capture_field_type): Build a DECLTYPE_TYPE
if the variable type uses 'auto'.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 57700f7..3699ea5 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -9078,7 +9078,8 @@ lambda_capture_field_type (tree expr)
{
tree type;
if (type_dependent_expression_p (expr)
- && !(TREE_TYPE (expr) && TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE))
+ && !(TREE_TYPE (expr) && TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE
+ && !type_uses_auto (TREE_TYPE (expr))))
{
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 0000000..013ed52
--- /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<class T>
+struct A
+{
+ void bar( ) { }
+
+ void foo( )
+ {
+ auto* this_ptr = this;
+ auto lc = [&]( )
+ {
+ this_ptr->bar();
+ };
+ lc();
+ }
+};
+
+int main()
+{
+ A<int> a;
+ a.foo();
+}