]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/57526 (use of X before deduction of auto error for seemingly good code)
authorJason Merrill <jason@redhat.com>
Tue, 9 Jul 2013 17:56:43 +0000 (13:56 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 9 Jul 2013 17:56:43 +0000 (13:56 -0400)
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
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto3.C [new file with mode: 0644]

index 68c6a09cff93004960e392a20ce638d14fe68977..9770f5b38c7b0229be7746bb7e6ef9770f8940bf 100644 (file)
@@ -1,5 +1,9 @@
 2013-07-09  Jason Merrill  <jason@redhat.com>
 
+       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.
index e06ac61bb800798787c9d240017bde6e9aff2927..fd6c819119173c15ff9e573fb22a7cfc8a17f5b7 100644 (file)
@@ -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 (file)
index 0000000..013ed52
--- /dev/null
@@ -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();
+}