https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124431

Nathaniel Shead <nshead at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=124311
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |nshead at gcc dot 
gnu.org

--- Comment #4 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
Had a look; the issue is that we're not correctly merging the FIELD_DECL we see
when reading the definition of mat<4> in B with the definition of mat<4> in C. 
This is because of the following hunk in trees_in::key_mergeable:

          case TYPE_DECL:
            gcc_checking_assert (!is_imported_temploid_friend);
            if (is_attached && !(state->is_module () || state->is_partition ())
                /* Implicit member functions can come from
                   anywhere.  */
                && !(DECL_ARTIFICIAL (decl)
                     && TREE_CODE (decl) == FUNCTION_DECL
                     && !DECL_THUNK_P (decl)))
              kind = "unique";
            else
              {

Since mat<4>::data is attached to a named module, we think it must be unique
and cannot be sourced from multiple modules at once.  But this is not true for
template specialisations, which can be instantiated in any TU.  We must handle
this case; something like the following perhaps:

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 6c6b566508f..5424c82ad21 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -12326,7 +12326,12 @@ trees_in::key_mergeable (int tag, merge_kind mk, tree
decl, tree inner,
                    anywhere.  */
                 && !(DECL_ARTIFICIAL (decl)
                      && TREE_CODE (decl) == FUNCTION_DECL
-                     && !DECL_THUNK_P (decl)))
+                     && !DECL_THUNK_P (decl))
+                /* As can members of template specialisations.  */
+                && !(TREE_CODE (container) != TEMPLATE_DECL
+                     && TYPE_TEMPLATE_INFO (TREE_TYPE (container))
+                     && TYPE_LANG_SPECIFIC (TREE_TYPE (container))
+                     && CLASSTYPE_USE_TEMPLATE (TREE_TYPE (container))))
               kind = "unique";
             else
               {

but I think there's probably a better way of doing this, and I'm not sure if
I've still missed some cases perhaps.

Reply via email to