https://gcc.gnu.org/g:e9ac6f861c459436695874617244a0fbd118ea78
commit r17-6237-ge9ac6f861c459436695874617244a0fbd118ea78 Author: Jason Merrill <[email protected]> Date: Tue Nov 10 22:42:04 2026 -0500 c++: keep contract wrappers out of modules Building contracts wrappers in module context caused multiple issues: trouble matching up built-in declarations of terminate, source_location, etc, and emitting multiple versions of the wrappers in an importing TU. All of these are fixed by moving them out of the module, effectively into a private module fragment. gcc/cp/ChangeLog: * decl2.cc (c_parse_final_cleanups): Build contract wrappers after finish_module_processing. Diff: --- gcc/cp/decl2.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index b1723b3d3050..ab68e4c46092 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -6116,17 +6116,18 @@ c_parse_final_cleanups (void) reconsider = true; } - if (flag_contracts) - { - emit_contract_wrapper_func (/*done*/true); - maybe_emit_violation_handler_wrappers (); - } - /* All templates have been instantiated. */ at_eof = 2; void *module_cookie = finish_module_processing (parse_in); + if (flag_contracts) + { + /* Keep these out of the module to avoid duplicate definitions. */ + emit_contract_wrapper_func (/*done*/true); + maybe_emit_violation_handler_wrappers (); + } + lower_var_init (); generate_mangling_aliases ();
