See <https://wg21.link/P2686R4>.
Created attachment 61661 [details] gcc16-pr117784-wip.patch Untested patch for the easy part of the paper (namely allowing constexpr and constinit (the latter we've been allowing quietly) and propagating it to the sb vars. The patch doesn't implement anything from the constant expression references/pointers changes, so with the patch constexpr & constinit sb work solely with namespace scope or static or the automatic non-tuple case without ref qualifiers.
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:c81447d969f27a8653ebb1a450372f0d25a2e628 commit r16-2108-gc81447d969f27a8653ebb1a450372f0d25a2e628 Author: Jakub Jelinek <jakub@redhat.com> Date: Tue Jul 8 19:21:55 2025 +0200 c++: Implement part of C++26 P2686R4 - constexpr structured bindings [PR117784] The following patch implements the constexpr structured bindings part of the P2686R4 paper, so the [dcl.pre], [dcl.struct.bind], [dcl.constinit] and first hunk in [dcl.constexpr] changes. The paper doesn't have a feature test macro and the constexpr structured binding part of it seems more-less self-contained, so I think it is useful to get this in independently from the rest. Of course, automatic constexpr/constinit structured bindings in the tuple cases or automatic constexpr/constinit structured bindings with auto & will not really work for now. Another reason for the split is that for C++ < 26, I think what the patch implements is basically what the users will see, i.e. we can accept constexpr or constinit structured binding with pedwarn, but I think we can't change the constant expression rules in C++ < 26. I plan to look at the rest of the paper. 2025-07-08 Jakub Jelinek <jakub@redhat.com> PR c++/117784 * decl.cc: Implement part of C++26 P2686R4 - constexpr structured bindings. (cp_finish_decl): Pedwarn for C++23 and older on constinit on structured bindings except for static/thread_local where it uses earlier error. (grokdeclarator): Pedwarn on constexpr structured bindings for C++23 and older instead of emitting error always, don't clear constexpr_p in that case. * parser.cc (cp_parser_decomposition_declaration): Copy over DECL_DECLARED_CONSTEXPR_P and DECL_DECLARED_CONSTINIT_P flags. * g++.dg/cpp1z/decomp3.C (test): For constexpr structured binding initialize from constexpr var instead of non-constexpr and expect just a pedwarn for C++23 and older instead of error always. * g++.dg/cpp26/decomp9.C (foo): Likewise. * g++.dg/cpp26/decomp22.C: New test. * g++.dg/cpp26/decomp23.C: New test. * g++.dg/cpp26/decomp24.C: New test. * g++.dg/cpp26/decomp25.C: New test.
As the commit message says, so far partially implemented. One can declare structured bindings constexpr as long as the C++23-ish constant expression handling allows that.
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:9956dc37cb3d71c1fc7a89b45cc291645c11817b commit r16-2264-g9956dc37cb3d71c1fc7a89b45cc291645c11817b Author: Jason Merrill <jason@redhat.com> Date: Tue Jul 15 10:46:41 2025 -0400 c++: decomp25 vs -fimplicit-constexpr [PR117784] Avoid diagnostic changes from -fimplicit-constexpr. PR c++/117784 gcc/testsuite/ChangeLog: * g++.dg/cpp26/decomp25.C: Add -fno-implicit-constexpr.
*** Bug 121521 has been marked as a duplicate of this bug. ***
*** Bug 122269 has been marked as a duplicate of this bug. ***