On 5/20/19 5:44 PM, Jakub Jelinek wrote:
Hi!
The following patch is an attempt at implementing these two papers.
I must be missing something important, because in P1091R3 the rationale
talks about the intent to support structured bindings with static,
thread_local, constexpr, inline and extern, but the actual wording
changes in the paper are only about static and thread_local, because dcl.dcl
still says
If the decl-specifier-seq contains any decl-specifier other than static,
thread_local, auto, or cv-qualifiers, the program is ill-formed.
Right, the original proposal was for more, but it was limited to static
and thread_local by the committee.
Another thing are the lambda captures of the structured bindings.
The end result is that they are allowed, both capturing values and capturing
references, except when capturing bitfields, but that is actually what gcc
has been implementing for quite a while. The question is if we shouldn't
reject those for -std=c++17 or -std=c++17 -pedantic-errors, seems e.g.
clang++ rejects those, but looking at the C++17 standard I don't see any
wording that would say those are not allowed. It was only P0588R1 that
added
"or captures a structured binding (explicitly or implicitly), the program is
ill-formed."
Is P0588R1 a DR that would be applied to older standards?
P0588 was certainly intended to apply to C++17, but I'd treat this as
overriding it, and not complain.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2019-05-20 Jakub Jelinek <ja...@redhat.com>
P1091R3 - Extending structured bindings to be more like var decls
P1381R1 - Reference capture of structured bindings
* decl.c (cp_maybe_mangle_decomp): Handle TREE_STATIC decls even at
function scope.
(cp_finish_decomp): Copy over various decl properties from decl to
v[i] in the tuple case.
(grokdeclarator): Allow static, thread_local and __thread for C++2a
and use pedwarn instead of error for older standard revisions.
Make other structured binding diagnostic messages more i18n friendly.
* g++.dg/cpp1z/decomp3.C (test): For static, expect only warning
instead of error and only for c++17_down. Add a thread_local test.
(z2): Add a __thread test.
* g++.dg/cpp2a/decomp1.C: New test.
* g++.dg/cpp2a/decomp1-aux.cc: New file.
* g++.dg/cpp2a/decomp2.C: New test.
* g++.dg/cpp2a/decomp3.C: New test.
--- gcc/cp/decl.c.jj 2019-05-20 14:52:26.871375569 +0200
+++ gcc/cp/decl.c 2019-05-20 15:48:33.563599150 +0200
+ && (DECL_NAMESPACE_SCOPE_P (decl) || TREE_STATIC (decl)))
> + if (TREE_STATIC (v[i]))
When can a structured binding not be TREE_STATIC?
Jason