re PR c++/78896 ([C++17] Segmentation fault occurs when use variable initialized...
authorJakub Jelinek <jakub@redhat.com>
Wed, 25 Jan 2017 22:36:18 +0000 (23:36 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 25 Jan 2017 22:36:18 +0000 (23:36 +0100)
PR c++/78896
* decl.c (cp_finish_decomp): Disallow memberwise decomposition of
lambda expressions.

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

From-SVN: r244909

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/decomp24.C [new file with mode: 0644]

index dc098b2a723b76bf780731b4cc7b9986f3c50695..6144ad77450aacd89e287ec4e9494fd5d583dcb8 100644 (file)
@@ -1,5 +1,9 @@
 2017-01-25  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/78896
+       * decl.c (cp_finish_decomp): Disallow memberwise decomposition of
+       lambda expressions.
+
        PR c++/77914
        * parser.c (cp_parser_lambda_declarator_opt): Pedwarn with
        OPT_Wpedantic on lambda templates for -std=c++14 and higher.
index af74dcdb7059ee48f5ee8a1a4f5a2cf0a347f21e..4b64ba13377f22afa322a3781fb9082e728d6b35 100644 (file)
@@ -7562,6 +7562,11 @@ cp_finish_decomp (tree decl, tree first, unsigned int count)
       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);
index e82fb4c94555e899d838ee092fd0269813506766..7c85a6b053cfbe11417ec6ab2fb8ac2485cc2fbc 100644 (file)
@@ -1,5 +1,8 @@
 2017-01-25  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/78896
+       * g++.dg/cpp1z/decomp24.C: New test.
+
        PR c++/77914
        * g++.dg/cpp1y/lambda-generic-77914.C: New test.
        * g++.dg/cpp1y/lambda-generic-dep.C: Add -pedantic to dg-options,
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp24.C b/gcc/testsuite/g++.dg/cpp1z/decomp24.C
new file mode 100644 (file)
index 0000000..0e874fa
--- /dev/null
@@ -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 }
+}