aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2017-01-25 23:36:18 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2017-01-25 23:36:18 +0100
commita25608aa6fc14c49fb23247f60c5f83225d00c29 (patch)
tree034ce782d295c7ad1b65b4864497021015d7218f
parent0e3438689a6ffc4851ba8162306e5a1709b3b905 (diff)
downloadgcc-a25608aa6fc14c49fb23247f60c5f83225d00c29.zip
gcc-a25608aa6fc14c49fb23247f60c5f83225d00c29.tar.gz
gcc-a25608aa6fc14c49fb23247f60c5f83225d00c29.tar.bz2
re PR c++/78896 ([C++17] Segmentation fault occurs when use variable initialized using structured binding with capture-by-ref lambda)
PR c++/78896 * decl.c (cp_finish_decomp): Disallow memberwise decomposition of lambda expressions. * g++.dg/cpp1z/decomp24.C: New test. From-SVN: r244909
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/decl.c5
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/decomp24.C11
4 files changed, 23 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index dc098b2..6144ad7 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index af74dcd..4b64ba1 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e82fb4c..7c85a6b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..0e874fa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/decomp24.C
@@ -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 }
+}