]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/56901 (lambda with implicit capture by reference)
authorJason Merrill <jason@redhat.com>
Thu, 11 Apr 2013 16:49:57 +0000 (12:49 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 11 Apr 2013 16:49:57 +0000 (12:49 -0400)
PR c++/56901
* semantics.c (lambda_capture_field_type, lambda_proxy_type):
Strip references before checking WILDCARD_TYPE_P.

From-SVN: r197819

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto2.C [new file with mode: 0644]

index e6670b247edc23e779a4ec280da5c5b8adbde61b..e2cf1b4bff133e8ecd68446048aa1fb40aa65783 100644 (file)
@@ -1,3 +1,9 @@
+2013-04-11  Jason Merrill  <jason@redhat.com>
+
+       PR c++/56901
+       * semantics.c (lambda_capture_field_type, lambda_proxy_type):
+       Strip references before checking WILDCARD_TYPE_P.
+
 2013-04-11  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * call.c (build_conditional_expr_1, build_over_call): Protect
index 3a558b0f67659a8e4372df0bf46d41a5511a2d95..063183308f285690040c75698afaaa382c2ce037 100644 (file)
@@ -9114,16 +9114,14 @@ lambda_function (tree lambda)
 tree
 lambda_capture_field_type (tree expr)
 {
-  tree type;
-  if (!TREE_TYPE (expr) || WILDCARD_TYPE_P (TREE_TYPE (expr)))
+  tree type = non_reference (unlowered_expr_type (expr));
+  if (!type || WILDCARD_TYPE_P (type))
     {
       type = cxx_make_type (DECLTYPE_TYPE);
       DECLTYPE_TYPE_EXPR (type) = expr;
       DECLTYPE_FOR_LAMBDA_CAPTURE (type) = true;
       SET_TYPE_STRUCTURAL_EQUALITY (type);
     }
-  else
-    type = non_reference (unlowered_expr_type (expr));
   return type;
 }
 
@@ -9324,7 +9322,7 @@ lambda_proxy_type (tree ref)
   if (REFERENCE_REF_P (ref))
     ref = TREE_OPERAND (ref, 0);
   type = TREE_TYPE (ref);
-  if (type && !WILDCARD_TYPE_P (type))
+  if (type && !WILDCARD_TYPE_P (non_reference (type)))
     return type;
   type = cxx_make_type (DECLTYPE_TYPE);
   DECLTYPE_TYPE_EXPR (type) = ref;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto2.C
new file mode 100644 (file)
index 0000000..05fadf5
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/56901
+// { dg-require-effective-target c++11 }
+
+template <typename>
+void foo_impl()
+{
+  int data;
+  auto L = [&](){ return data; };
+  [&](){ L(); }();
+  [&L](){ L(); }();
+}
+
+void foo()
+{
+  foo_impl<int>();
+}