summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2017-12-15 22:07:23 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2017-12-15 22:07:23 +0000
commit11c94ab9fc1ed9c0d72f9ed569c5c8c97ba24fd8 (patch)
tree9071b43d30e8da412d09fc71b56f6f36f06abb83
parent664ea9b0f4dd43242caa1baa8770abf6e068382e (diff)
downloadgcc-11c94ab9fc1ed9c0d72f9ed569c5c8c97ba24fd8.tar.gz
Backported from mainline
2017-11-27 Jakub Jelinek <jakub@redhat.com> PR c++/81888 * parser.c (cp_parser_decomposition_declaration): Reject just BRACE_ENCLOSED_INITIALIZER_P initializers with nelts != 1 rather than all such CONSTRUCTORs, and only if is_direct_init is true. * g++.dg/cpp1z/decomp30.C: Add a test for structured binding with = {} and = { a, a } initializers. * g++.dg/cpp1z/decomp31.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@255719 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/parser.c3
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/decomp30.C2
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/decomp31.C18
5 files changed, 32 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c303347f075..a47d90bc96d 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -3,6 +3,11 @@
Backported from mainline
2017-11-27 Jakub Jelinek <jakub@redhat.com>
+ PR c++/81888
+ * parser.c (cp_parser_decomposition_declaration): Reject just
+ BRACE_ENCLOSED_INITIALIZER_P initializers with nelts != 1 rather
+ than all such CONSTRUCTORs, and only if is_direct_init is true.
+
PR c++/81675
* cp-gimplify.c (cp_fold) <case COND_EXPR>: Don't return immediately
for VOID_TYPE_P COND_EXPRs, instead fold the operands and if op0 is
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index b060ac8dcd1..4509397e414 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -13048,7 +13048,8 @@ cp_parser_decomposition_declaration (cp_parser *parser,
if (initializer == NULL_TREE
|| (TREE_CODE (initializer) == TREE_LIST
&& TREE_CHAIN (initializer))
- || (TREE_CODE (initializer) == CONSTRUCTOR
+ || (is_direct_init
+ && BRACE_ENCLOSED_INITIALIZER_P (initializer)
&& CONSTRUCTOR_NELTS (initializer) != 1))
{
error_at (loc, "invalid initializer for structured binding "
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e312f0f0121..c8ef0b39442 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -3,6 +3,11 @@
Backported from mainline
2017-11-27 Jakub Jelinek <jakub@redhat.com>
+ PR c++/81888
+ * g++.dg/cpp1z/decomp30.C: Add a test for structured binding with
+ = {} and = { a, a } initializers.
+ * g++.dg/cpp1z/decomp31.C: New test.
+
PR c++/81675
* g++.dg/warn/pr81675.C: New test.
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp30.C b/gcc/testsuite/g++.dg/cpp1z/decomp30.C
index 23115ad1082..cca15ed126b 100644
--- a/gcc/testsuite/g++.dg/cpp1z/decomp30.C
+++ b/gcc/testsuite/g++.dg/cpp1z/decomp30.C
@@ -10,3 +10,5 @@ auto [j, k] { a, a }; // { dg-error "invalid initializer for structured binding
auto [l, m] = { a }; // { dg-error "deducing from brace-enclosed initializer list requires" }
auto [n, o] {}; // { dg-error "invalid initializer for structured binding declaration" }
auto [p, q] (); // { dg-error "invalid initializer for structured binding declaration" }
+auto [r, s] = {}; // { dg-error "deducing from brace-enclosed initializer list requires" }
+auto [t, u] = { a, a }; // { dg-error "deducing from brace-enclosed initializer list requires" }
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp31.C b/gcc/testsuite/g++.dg/cpp1z/decomp31.C
new file mode 100644
index 00000000000..04b2516dada
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/decomp31.C
@@ -0,0 +1,18 @@
+// PR c++/81888
+// { dg-do compile { target c++1z } }
+
+struct S {
+ bool s = true;
+};
+
+auto [a] = S{};
+
+template <class T>
+bool
+foo () noexcept
+{
+ auto [c] = T{};
+ return c;
+}
+
+const bool b = foo<S> ();