re PR c++/81888 (Structured bindings stopped working)
authorJakub Jelinek <jakub@redhat.com>
Mon, 27 Nov 2017 21:54:25 +0000 (22:54 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 27 Nov 2017 21:54:25 +0000 (22:54 +0100)
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.

From-SVN: r255180

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

index 91de626f9100e0adb4fcf72dffc8c739d82fdea8..a5735eb71a659007933b573fa7a915845b392877 100644 (file)
@@ -1,3 +1,10 @@
+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.
+
 2017-11-27  Jason Merrill  <jason@redhat.com>
 
        * pt.c (primary_template_specialization_p): Rename from
index 847ad1464e1b6214e6ed43f47a87007e15d2e565..eae73fcab2fd4ae0708240c492dd1e09af2cc159 100644 (file)
@@ -13382,7 +13382,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 "
index bfcf7b19cdc8ec3079ebe6447b19ed97bdbf187b..8203f5c0590d11ca96dc22c15df8ac19a1545d42 100644 (file)
@@ -1,3 +1,10 @@
+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.
+
 2017-11-27  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        PR middle_end/82333
index 73068712d5f55f8a244ac73cdc599cd6e93e489e..b11a3127777a39554557625dc6df201075663da8 100644 (file)
@@ -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 (file)
index 0000000..ebc44b4
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/81888
+// { dg-do compile { target c++17 } }
+
+struct S {
+  bool s = true;
+};
+
+auto [a] = S{};
+
+template <class T>
+bool
+foo () noexcept
+{
+  auto [c] = T{};
+  return c;
+}
+
+const bool b = foo<S> ();