]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: lambda capturing structured bindings [PR85889]
authorMarek Polacek <polacek@redhat.com>
Fri, 1 Mar 2024 22:13:02 +0000 (17:13 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 9 May 2024 16:42:42 +0000 (12:42 -0400)
commit46bafd9a6b9b776142e0b1424a6ac02e3a2fd300
tree54ee9d969755a48700bab41f2624a31048047eea
parent80d1e2ec4d394111ebd50d2e8928f7596b7b5c7e
c++: lambda capturing structured bindings [PR85889]

<https://wg21.link/p1381r1> clarifies that it's OK to capture structured
bindings.

[expr.prim.lambda.capture]/4 says "The identifier in a simple-capture shall
denote a local entity" and [basic.pre]/3: "An entity is a [...] structured
binding".

It doesn't appear that this was made a DR, so, strictly speaking, we
should have a -Wc++20-extensions warning, like clang++.

PR c++/85889

gcc/cp/ChangeLog:

* lambda.cc (add_capture): Add a pedwarn for capturing structured
bindings.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/decomp3.C: Use -Wno-c++20-extensions.
* g++.dg/cpp1z/decomp60.C: New test.
gcc/cp/lambda.cc
gcc/testsuite/g++.dg/cpp1z/decomp60.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/decomp3.C