From 11c94ab9fc1ed9c0d72f9ed569c5c8c97ba24fd8 Mon Sep 17 00:00:00 2001 From: jakub Date: Fri, 15 Dec 2017 22:07:23 +0000 Subject: Backported from mainline 2017-11-27 Jakub Jelinek 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 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/parser.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp1z/decomp30.C | 2 ++ gcc/testsuite/g++.dg/cpp1z/decomp31.C | 18 ++++++++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/decomp31.C 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 + 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) : 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 + 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 +bool +foo () noexcept +{ + auto [c] = T{}; + return c; +} + +const bool b = foo (); -- cgit v1.2.1