https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99000
--- Comment #20 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Jason Merrill <[email protected]>: https://gcc.gnu.org/g:13920d004da35b536d6ef07b0a32c0d3acc4c889 commit r17-4959-g13920d004da35b536d6ef07b0a32c0d3acc4c889 Author: Jason Merrill <[email protected]> Date: Wed Oct 7 10:03:47 2026 -0400 c++/modules: P1811: relaxing redefinition restrictions [PR99000] P1811 says it's OK to redefine an imported global module entity in a different translation unit. The simplest (and fastest) way to handle that is skipping the tokens of the redundant definition. At some later point we might want to optionally parse the new definition and compare it to the imported one for ODR checking, but it isn't necessary for supporting well-formed code. This does allow wildly ill-formed code in the redefinitions for the sake of speed, on the assumption that the the definitions satisfy the ODR, probably because they are from the same source code. The core addition is redefinable_import_p; various places that have errored about redefinition now discard the redefinition if it is true. For convenience, I'm also adding -fno-module-include-translate to use to force textual inclusion in compile-std1.C. For redefinition of classes, I've gone back and forth between trying to merge reachable non-exports in lookup_elaborated_type (as with the __class_type_info hack removed by this patch) or waiting until check_module_override. I eventually settled on the latter approach for consistency, but it does mean that we need to check for a previous definition after lookup and again after push. This patch wrongly allows multiple redefinitions after an import, as in p1811-5. I expect that fixing this should mostly mean clarifying what DECL_MODULE_IMPORT_P means for global module entities, but additional machinery would be needed for default arguments. And it doesn't seem necessary to fix in this patch, given that I'm deliberately allowing other ill-formed redefinitions; if a shared header has multiple definitions, we will diagnose it when building the imported module. Assisted-by: GPT-5.6 Sol (p1811* testcases) P1811 PR c++/99000 gcc/c-family/ChangeLog: * c.opt (fmodule-include-translate): New option. gcc/cp/ChangeLog: * module.cc (maybe_translate_include): Check -fmodule-include-translate. * name-lookup.cc (redefinable_import_p): New. (pushdecl): Check DECL_IS_UNDECLARED_BUILTIN instead of hidden_p. (lookup_elaborated_type): Don't special-case cxxabi classes. (pushtag): Handle pushdecl finding a previous definition. * decl.cc (merge_default_template_args): Check redefinable_import_p. (duplicate_decls, grokfndecl, start_enum): Likewise. (redeclaration_error_message): Likewise. * parser.cc (cp_parser_skip_to_end_of_balanced_tokens): New. (cp_parser_skip_function_definition): New. (cp_parser_skip_base_clause): New. (cp_parser_enum_specifier): Skip redundant definition. (cp_parser_class_specifier): Likewise. (cp_parser_class_head): Likewise. (cp_parser_function_definition_from_specifiers_and_declarator): Likewise. * pt.cc (redeclare_class_template): Adjust. * cp-tree.h: Adjust. * name-lookup.h: Adjust. gcc/testsuite/ChangeLog: * g++.dg/modules/compile-std1.C: Also test #include after import. * g++.dg/modules/hello-1_b.C: Likewise. * g++.dg/modules/default-arg-4_b.C: Remove xfails. * g++.dg/modules/pr122053_b.C: Likewise. * g++.dg/modules/gmf-3.h: New test. * g++.dg/modules/gmf-3_a.C: New test. * g++.dg/modules/gmf-3_b.C: New test. * g++.dg/modules/gmf-4_a.C: New test. * g++.dg/modules/gmf-4_b.C: New test.
