Skip to content

Commit bdc0472

Browse files
author
jakub
committed
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/trunk@255180 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 681f91a commit bdc0472

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

gcc/cp/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2017-11-27 Jakub Jelinek <[email protected]>
2+
3+
PR c++/81888
4+
* parser.c (cp_parser_decomposition_declaration): Reject just
5+
BRACE_ENCLOSED_INITIALIZER_P initializers with nelts != 1 rather
6+
than all such CONSTRUCTORs, and only if is_direct_init is true.
7+
18
2017-11-27 Jason Merrill <[email protected]>
29

310
* pt.c (primary_template_specialization_p): Rename from

gcc/cp/parser.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13382,7 +13382,8 @@ cp_parser_decomposition_declaration (cp_parser *parser,
1338213382
if (initializer == NULL_TREE
1338313383
|| (TREE_CODE (initializer) == TREE_LIST
1338413384
&& TREE_CHAIN (initializer))
13385-
|| (TREE_CODE (initializer) == CONSTRUCTOR
13385+
|| (is_direct_init
13386+
&& BRACE_ENCLOSED_INITIALIZER_P (initializer)
1338613387
&& CONSTRUCTOR_NELTS (initializer) != 1))
1338713388
{
1338813389
error_at (loc, "invalid initializer for structured binding "

gcc/testsuite/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2017-11-27 Jakub Jelinek <[email protected]>
2+
3+
PR c++/81888
4+
* g++.dg/cpp1z/decomp30.C: Add a test for structured binding with
5+
= {} and = { a, a } initializers.
6+
* g++.dg/cpp1z/decomp31.C: New test.
7+
18
2017-11-27 Michael Meissner <[email protected]>
29

310
PR middle_end/82333

gcc/testsuite/g++.dg/cpp1z/decomp30.C

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ auto [j, k] { a, a }; // { dg-error "invalid initializer for structured binding
1010
auto [l, m] = { a }; // { dg-error "deducing from brace-enclosed initializer list requires" }
1111
auto [n, o] {}; // { dg-error "invalid initializer for structured binding declaration" }
1212
auto [p, q] (); // { dg-error "invalid initializer for structured binding declaration" }
13+
auto [r, s] = {}; // { dg-error "deducing from brace-enclosed initializer list requires" }
14+
auto [t, u] = { a, a }; // { dg-error "deducing from brace-enclosed initializer list requires" }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// PR c++/81888
2+
// { dg-do compile { target c++17 } }
3+
4+
struct S {
5+
bool s = true;
6+
};
7+
8+
auto [a] = S{};
9+
10+
template <class T>
11+
bool
12+
foo () noexcept
13+
{
14+
auto [c] = T{};
15+
return c;
16+
}
17+
18+
const bool b = foo<S> ();

0 commit comments

Comments
 (0)