]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Implement for namespace statics CWG 2867 - Order of initialization for structure...
authorJakub Jelinek <jakub@redhat.com>
Mon, 27 Jan 2025 15:45:56 +0000 (16:45 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 27 Jan 2025 15:45:56 +0000 (16:45 +0100)
commitad8e6a4ada0a7ed73ac99404ff2b41ed9dc5e940
tree17c9791ff5a17e8dd151ec56e45092388e54eae6
parent6a510dea7f3b047d0650a48e558a4911973930eb
c++: Implement for namespace statics CWG 2867 - Order of initialization for structured bindings [PR115769]

The following patch adds CWG 2867 support for namespace locals.

Those vars are just pushed into {static,tls}_aggregates chain, then
pruned from those lists, separated by priority and finally emitted into
the corresponding dynamic initialization functions.
The patch adds two flags used on the TREE_LIST nodes in those lists,
one marks the structured binding base variable and/or associated ref
extended temps, another marks the vars initialized using get methods.
The flags are preserved across the pruning, for splitting into by priority
all associated decls of a structured binding using tuple* are forced
into the same priority as the first one, and finally when actually emitting
code, CLEANUP_POINT_EXPRs are disabled in the base initializer(s) and
code from the bases and non-bases together is wrapped into a single
CLEANUP_POINT_EXPR.

2025-01-27  Jakub Jelinek  <jakub@redhat.com>

PR c++/115769
gcc/cp/
* cp-tree.h (STATIC_INIT_DECOMP_BASE_P): Define.
(STATIC_INIT_DECOMP_NONBASE_P): Define.
* decl.cc (cp_finish_decl): Mark nodes in {static,tls}_aggregates
emitted for namespace scope structured bindings with
STATIC_INIT_DECOMP_{,NON}BASE_P flags when needed.
* decl2.cc (decomp_handle_one_var, decomp_finalize_var_list): New
functions.
(emit_partial_init_fini_fn): Use them.
(prune_vars_needing_no_initialization): Assert
STATIC_INIT_DECOMP_*BASE_P is not set on DECL_EXTERNAL vars to be
pruned out.
(partition_vars_for_init_fini): Use same priority for
consecutive STATIC_INIT_DECOMP_*BASE_P vars and propagate
those flags to new TREE_LISTs when possible.  Formatting fix.
(handle_tls_init): Use decomp_handle_one_var and
decomp_finalize_var_list functions.
gcc/testsuite/
* g++.dg/DRs/dr2867-5.C: New test.
* g++.dg/DRs/dr2867-6.C: New test.
* g++.dg/DRs/dr2867-7.C: New test.
* g++.dg/DRs/dr2867-8.C: New test.
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/decl2.cc
gcc/testsuite/g++.dg/DRs/dr2867-5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/DRs/dr2867-6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/DRs/dr2867-7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/DRs/dr2867-8.C [new file with mode: 0644]