Le 02/09/2026 à 18:40, Paul Richard Thomas a écrit :
Hello Mikael,
Please find the patch attached, which BTW is what I normally do :-)
Cheers
Paul
Thanks. See below.
diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc
index b79db02a30c..f0101de049e 100644
--- a/gcc/fortran/module.cc
+++ b/gcc/fortran/module.cc
@@ -5746,6 +5745,58 @@ read_cleanup (pointer_info *p)
}
+/* Reconstruct PDT parameter namespaces after all needed module symbols have
+ been loaded. read_cleanup installs named symtrees for the type-parameter
+ symbols first. */
+
+static void
+fixup_pdt_parameter_namespaces (pointer_info *p)
+{
+ gfc_symbol *sym;
+ gfc_formal_arglist *f, *fp;
+ gfc_namespace *ns;
+ gfc_symbol *super;
+
+ if (p == NULL)
+ return;
+
+ fixup_pdt_parameter_namespaces (p->left);
+ fixup_pdt_parameter_namespaces (p->right);
+
+ if (p->type != P_SYMBOL || p->u.rsym.state != USED)
+ return;
+
+ sym = p->u.rsym.sym;
+ if (sym == NULL
+ || !sym->attr.pdt_template
+ || sym->f2k_derived == NULL
+ || sym->f2k_derived->sym_root != NULL)
+ return;
+
+/* Transfer the sym_root of the namespace containing locally-declared PDT
+ type-parameter symbols to that the derived type's namespace. */
+ if (sym == NULL || !sym->attr.pdt_template || sym->f2k_derived == NULL
+ || sym->f2k_derived->sym_root != NULL)
+ return;
This condition is redundant with the previous one.
OK with that fixed.
One more comment...
+
+ f = sym->formal;
+ super = gfc_get_derived_super_type (sym);
+ if (super && super->attr.pdt_template)
+ for (fp = super->formal; fp && f; fp = fp->next)
+ f = f->next;
+
+ if (f == NULL || f->sym == NULL || f->sym->ns == NULL
+ || f->sym->ns->sym_root == NULL)
+ return;
+
+ ns = f->sym->ns;
+ sym->f2k_derived->sym_root = ns->sym_root;
+ ns->sym_root = NULL;
+ ns->refs++;
+ gfc_free_namespace (ns);
... this two lines sequence moved from mio_f2k_derived is probably
useless, unless ns->refs is zero before it, which is probably not the
case, as gfc_get_namespace immediately sets it to one.
+}
+
+
/* It is not quite enough to check for ambiguity in the symbols by
the loaded symbol and the new symbol not being identical. */
static bool