public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Reject lambda closure types in decompositions (PR c++/78896)
@ 2017-01-25 21:12 Jakub Jelinek
  2017-01-25 22:41 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-01-25 21:12 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ PATCH] Reject lambda closure types in decompositions (PR c++/78896)
  2017-01-25 21:12 [C++ PATCH] Reject lambda closure types in decompositions (PR c++/78896) Jakub Jelinek
@ 2017-01-25 22:41 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2017-01-25 22:41 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches List

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-25 22:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-25 21:12 [C++ PATCH] Reject lambda closure types in decompositions (PR c++/78896) Jakub Jelinek
2017-01-25 22:41 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).