return;
}
- if (unsigned m = get_originating_module (decl))
+ int m = get_originating_module (decl, /*global=-1*/true);
+ if (m > 0)
if (const char *n = module_name (m, false))
{
pp_character (pp, '@');
return decl;
}
+/* If DECL is imported, return which module imported it, or 0 for the current
+ module. Except that if GLOBAL_M1, return -1 for decls attached to the
+ global module. */
+
int
-get_originating_module (tree decl, bool for_mangle)
+get_originating_module (tree decl, bool global_m1)
{
tree owner = get_originating_module_decl (decl);
tree not_tmpl = STRIP_TEMPLATE (owner);
if (!DECL_LANG_SPECIFIC (not_tmpl))
- return for_mangle ? -1 : 0;
+ return global_m1 ? -1 : 0;
- if (for_mangle && !DECL_MODULE_ATTACH_P (not_tmpl))
+ if (global_m1 && !DECL_MODULE_ATTACH_P (not_tmpl))
return -1;
int mod = !DECL_MODULE_IMPORT_P (not_tmpl) ? 0 : get_importing_module (owner);
- gcc_checking_assert (!for_mangle || !(*modules)[mod]->is_header ());
+ gcc_checking_assert (!global_m1 || !(*modules)[mod]->is_header ());
return mod;
}
tree inner = DECL_TEMPLATE_RESULT (friend_tmpl);
if (!DECL_LANG_SPECIFIC (inner)
- || !DECL_MODULE_IMPORT_P (inner))
+ || !DECL_MODULE_ENTITY_P (inner))
return NULL_TREE;
lazy_load_pendings (friend_tmpl);
if (!bind)
return NULL_TREE;
- /* We're only interested in declarations coming from the same module
- of the friend class we're attempting to instantiate. */
- int m = get_originating_module (friend_tmpl);
+ /* We're only interested in declarations attached to the same module
+ as the friend class we're attempting to instantiate. */
+ int m = get_originating_module (friend_tmpl, /*global=-1*/true);
gcc_assert (m != 0);
/* There should be at most one class template from the module we're
looking for, return it. */
for (ovl_iterator iter (bind); iter; ++iter)
if (DECL_CLASS_TEMPLATE_P (*iter)
- && get_originating_module (*iter) == m)
+ && get_originating_module (*iter, true) == m)
return *iter;
return NULL_TREE;
--- /dev/null
+// PR c++/118920
+
+template <typename> struct unique_ptr {
+ template <typename> friend class out_ptr_t;
+};
+template <typename> struct shared_ptr {
+ template <typename> friend class out_ptr_t;
+};
--- /dev/null
+// PR c++/118920
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi M }
+
+module;
+#include "tpl-friend-17.h"
+export module M;
+unique_ptr<int> s;
+export template <typename> void foo() { shared_ptr<int> u; }
--- /dev/null
+// PR c++/118920
+// { dg-additional-options "-fmodules" }
+
+#include "tpl-friend-17.h"
+import M;
+
+int main() {
+ // instantiating shared_ptr<int> should find previously generated
+ // out_ptr_t template from the unique_ptr<int> instantiation
+ foo<int>();
+}