Bug 81888 - [7 Regression] Structured bindings stopped working
Summary: [7 Regression] Structured bindings stopped working
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.2.0
: P2 normal
Target Milestone: 7.3
Assignee: Jakub Jelinek
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2017-08-18 13:09 UTC by Antony Polukhin
Modified: 2017-12-16 08:58 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.1.0
Known to fail: 7.2.0
Last reconfirmed: 2017-08-18 00:00:00


Attachments
gcc8-pr81888.patch (835 bytes, patch)
2017-11-23 14:36 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antony Polukhin 2017-08-18 13:09:34 UTC
The following code worked well on GCC-7.1, but fails on GCC-7.2 with -std=c++17:



struct do_not_define_std_tuple_size_for_me {
  bool test1 = true;
};

template <class T>
bool is_structured_bindings_work() noexcept {
  auto [a] = T{};
  return a;
}

const bool do_not_use = is_structured_bindings_work<do_not_define_std_tuple_size_for_me>();



Error message:
error: invalid initializer for structured binding declaration
   auto [a] = T{};
        ^~~

Fix from Bug 78939 does not resolves the issue. Clang-4.0 and GCC-7.1 compile the code well.
Comment 1 Richard Biener 2017-08-18 13:29:12 UTC
Confirmed.  The feature was new in GCC 7.
Comment 2 Jakub Jelinek 2017-11-23 12:13:25 UTC
Started with my r249947 aka PR81258 fix.
Comment 3 Jakub Jelinek 2017-11-23 14:36:25 UTC
Created attachment 42696 [details]
gcc8-pr81888.patch

Untested fix.
Comment 4 Jakub Jelinek 2017-11-27 21:54:57 UTC
Author: jakub
Date: Mon Nov 27 21:54:25 2017
New Revision: 255180

URL: https://gcc.gnu.org/viewcvs?rev=255180&root=gcc&view=rev
Log:
	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.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1z/decomp31.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp1z/decomp30.C
Comment 5 Jakub Jelinek 2017-11-27 22:04:04 UTC
Fixed on the trunk so far.
Comment 6 Jakub Jelinek 2017-12-15 22:07:54 UTC
Author: jakub
Date: Fri Dec 15 22:07:23 2017
New Revision: 255719

URL: https://gcc.gnu.org/viewcvs?rev=255719&root=gcc&view=rev
Log:
	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.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp1z/decomp31.C
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/parser.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp1z/decomp30.C
Comment 7 Jakub Jelinek 2017-12-16 08:58:31 UTC
Fixed for 7.3+.