aboutsummaryrefslogtreecommitdiff
path: root/libcpp/init.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-04-30 08:57:15 +0200
committerJakub Jelinek <jakub@redhat.com>2024-04-30 08:57:15 +0200
commitbd35a92f8d44e91c96e8b6f01805fe4a68acf9eb (patch)
tree045352f2e02dfdb461ec8bf3b2e1643e09ffd005 /libcpp/init.cc
parent4d3a5618de5a949c61605f545f90e81bc0000502 (diff)
downloadgcc-bd35a92f8d44e91c96e8b6f01805fe4a68acf9eb.zip
gcc-bd35a92f8d44e91c96e8b6f01805fe4a68acf9eb.tar.gz
gcc-bd35a92f8d44e91c96e8b6f01805fe4a68acf9eb.tar.bz2
c++: Implement C++26 P0609R3 - Attributes for Structured Bindings [PR114456]
The following patch implements the P0609R3 paper; we build the VAR_DECLs for the structured binding identifiers early, so all we need IMHO is just to parse the attributed identifier list and pass the attributes to the VAR_DECL creation. The paper mentions maybe_unused and gnu::nonstring attributes as examples where they can be useful. Not sure about either of them. For maybe_unused, the thing is that both GCC and clang already don't diagnose maybe unused for the structured binding identifiers, because it would be a false positive too often; and there is no easy way to find out if a structured binding has been written with the P0609R3 paper in mind or not (maybe we could turn it on if in the structured binding is any attribute, even if just [[]] and record that as a flag on the whole underlying decl, so that we'd diagnose auto [a, b, c[[]]] = d; // use a, c but not b but not auto [e, f, g] = d; // use a, c but not b ). For gnu::nonstring, the issue is that we currently don't allow the attribute on references to char * or references to char[], just on char */char[]. I've filed a PR for that. The first testcase in the patch tests it on [[]] and [[maybe_unused]], just whether it is parsed properly, second on gnu::deprecated, which works. Haven't used deprecated attribute because the paper said that attribute is for further investigation. 2024-04-30 Jakub Jelinek <jakub@redhat.com> PR c++/114456 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Predefine __cpp_structured_bindings for C++26 to 202403L rather than 201606L. gcc/cp/ * parser.cc (cp_parser_decomposition_declaration): Implement C++26 P0609R3 - Attributes for Structured Bindings. Parse attributed identifier lists for structured binding declarations, pass the attributes to start_decl. gcc/testsuite/ * g++.dg/cpp26/decomp1.C: New test. * g++.dg/cpp26/decomp2.C: New test. * g++.dg/cpp26/feat-cxx26.C (__cpp_structured_bindings): Expect 202403 rather than 201606.
Diffstat (limited to 'libcpp/init.cc')
0 files changed, 0 insertions, 0 deletions