]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Implement __builtin_structured_binding_size trait master trunk
authorJakub Jelinek <jakub@redhat.com>
Fri, 15 Aug 2025 20:38:41 +0000 (22:38 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 15 Aug 2025 20:38:41 +0000 (22:38 +0200)
commit9a8b436b005b56e5ec3d8274284ae3afb4e7ba72
treeb0084c6b0fe6ece925ff51dad7480a81011a091e
parent91b5fc4ae2e5c8693cc0b619562f15f90c0fdfaa
c++: Implement __builtin_structured_binding_size trait

clang++ apparently added a SFINAE-friendly __builtin_structured_binding_size
trait to return the structured binding size (or error if not in SFINAE
contexts if a type doesn't have a structured binding size).

The expansion statement patch already anticipated this through adding
complain argument to cp_finish_decomp.

The following patch implements it.

2025-08-15  Jakub Jelinek  <jakub@redhat.com>

gcc/
* doc/extend.texi (Type Traits): Document
__builtin_structured_binding_size.
gcc/cp/
* cp-trait.def (STRUCTURED_BINDING_SIZE): New unary trait.
* cp-tree.h (finish_structured_binding_size): Declare.
* semantics.cc (trait_expr_value): Handle
CPTK_STRUCTURED_BINDING_SIZE.
(finish_structured_binding_size): New function.
(finish_trait_expr): Handle CPTK_RANK and CPTK_TYPE_ORDER
in the switch instead of just doing break; for those and
ifs at the end to handle them.  Handle CPTK_STRUCTURED_BINDING_SIZE.
* pt.cc (tsubst_expr): Likewise.
* constraint.cc (diagnose_trait_expr): Likewise.
* decl.cc (get_tuple_size): Use mce_true for maybe_const_value.
(cp_decomp_size): Diagnose incomplete types not just if
processing_template_decl, and use error_at instead of pedwarn.
If btype is NULL, just return 0 instead of diagnosing an error.
gcc/testsuite/
* g++.dg/cpp26/expansion-stmt15.C: Expect different diagnostics
for zero size destructuring expansion statement.
* g++.dg/ext/builtin-structured-binding-size1.C: New test.
* g++.dg/ext/builtin-structured-binding-size2.C: New test.
* g++.dg/ext/builtin-structured-binding-size3.C: New test.
* g++.dg/ext/builtin-structured-binding-size4.C: New test.
12 files changed:
gcc/cp/constraint.cc
gcc/cp/cp-trait.def
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/pt.cc
gcc/cp/semantics.cc
gcc/doc/extend.texi
gcc/testsuite/g++.dg/cpp26/expansion-stmt15.C
gcc/testsuite/g++.dg/ext/builtin-structured-binding-size1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin-structured-binding-size2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin-structured-binding-size3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin-structured-binding-size4.C [new file with mode: 0644]