diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 8aab9ea0bae..4e91fa6e052 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -7649,6 +7649,19 @@ trees_in::install_entity (tree decl) gcc_checking_assert (!existed); slot = ident; } + else if (state->is_partition ()) + { + /* The decl is already in the entity map, but we see it again now from a + partition: we want to overwrite if the original decl wasn't also from + a (possibly different) partition. Otherwise, for things like template + instantiations, make_dependency might not realise that this is also + provided from a partition and should be considered part of this module + (and thus always emitted into the primary interface's CMI). */ + unsigned *slot = entity_map->get (DECL_UID (decl)); + module_state *imp = import_entity_module (*slot); + if (!imp->is_partition ()) + *slot = ident; + } return true; } diff --git a/gcc/testsuite/g++.dg/modules/pr99377-3_a.H b/gcc/testsuite/g++.dg/modules/pr99377-3_a.H new file mode 100644 index 00000000000..580a7631ae1 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99377-3_a.H @@ -0,0 +1,17 @@ +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +template +struct Widget +{ + Widget (int) { } + + bool First() const { return true; } + + bool Second () const { return true;} +}; + +inline void Frob (const Widget& w) noexcept +{ + w.First (); +} diff --git a/gcc/testsuite/g++.dg/modules/pr99377-3_b.C b/gcc/testsuite/g++.dg/modules/pr99377-3_b.C new file mode 100644 index 00000000000..5cbce7b3544 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99377-3_b.C @@ -0,0 +1,10 @@ +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi Foo:check } + +export module Foo:check; +import "pr99377-3_a.H"; + +export inline bool Check (const Widget& w) +{ + return w.Second (); +} diff --git a/gcc/testsuite/g++.dg/modules/pr99377-3_c.C b/gcc/testsuite/g++.dg/modules/pr99377-3_c.C new file mode 100644 index 00000000000..fa7c24203bd --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99377-3_c.C @@ -0,0 +1,5 @@ +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi Foo } + +export module Foo; +export import :check; diff --git a/gcc/testsuite/g++.dg/modules/pr99377-3_d.C b/gcc/testsuite/g++.dg/modules/pr99377-3_d.C new file mode 100644 index 00000000000..cb1f28321b1 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99377-3_d.C @@ -0,0 +1,8 @@ +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts" } + +import Foo; + +int main() { + return Check(0) ? 0 : 1; +}