Hi!

As discussed in the PR, while lambda closure types are class types, it
is implementation dependent on what those class types actually contain,
allowing that to be decomposed is just weird.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-01-25  Jakub Jelinek  <ja...@redhat.com>

        PR c++/78896
        * decl.c (cp_finish_decomp): Disallow memberwise decomposition of
        lambda expressions.

        * g++.dg/cpp1z/decomp24.C: New test.

--- gcc/cp/decl.c.jj    2017-01-25 17:17:51.000000000 +0100
+++ gcc/cp/decl.c       2017-01-25 19:16:19.439879509 +0100
@@ -7562,6 +7562,11 @@ cp_finish_decomp (tree decl, tree first,
       error_at (loc, "cannot decompose non-array non-class type %qT", type);
       goto error_out;
     }
+  else if (LAMBDA_TYPE_P (type))
+    {
+      error_at (loc, "cannot decompose lambda closure type %qT", type);
+      goto error_out;
+    }
   else
     {
       tree btype = find_decomp_class_base (loc, type, NULL_TREE);
--- gcc/testsuite/g++.dg/cpp1z/decomp24.C.jj    2017-01-25 19:19:42.536296515 
+0100
+++ gcc/testsuite/g++.dg/cpp1z/decomp24.C       2017-01-25 19:19:20.000000000 
+0100
@@ -0,0 +1,11 @@
+// PR c++/78896
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+int
+foo ()
+{
+  int a {10};
+  auto [b] { [&a](){} };       // { dg-error "cannot decompose lambda closure 
type" }
+  return b - a;                        // { dg-warning "decomposition 
declaration only available with" "" { target c++14_down } .-1 }
+}

        Jakub

Reply via email to