diff mbox

[C++] Reject lambda closure types in decompositions (PR c++/78896)

Message ID 20170125210744.GT1867@tucnak
State New
Headers show

Commit Message

Jakub Jelinek Jan. 25, 2017, 9:07 p.m. UTC
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  <jakub@redhat.com>

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

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


	Jakub

Comments

Jason Merrill Jan. 25, 2017, 10:14 p.m. UTC | #1
OK.

On Wed, Jan 25, 2017 at 4:07 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> 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  <jakub@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
diff mbox

Patch

--- 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 }
+}