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

--- Comment #4 from anlauf at gcc dot gnu.org ---
The patch in comment#3 tries to fix a symptom and is wrong.  The true cause
is the attempt to derive the formal argument typespec from the actual for
intrinsics.  This mistreats character, as the actual might be deferred-length.

Better fix:

diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index 37a9e8fa0ae..18d0fde8319 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -4725,6 +4731,13 @@ gfc_copy_formal_args_intr (gfc_symbol *dest,
gfc_intrinsic_sym *src,
       formal_arg->sym->attr.flavor = FL_VARIABLE;
       formal_arg->sym->attr.dummy = 1;

+      /* Be careful not to treat an actual deferred-length character
+        argument wrongly as template for the formal argument.  */
+      if (formal_arg->sym->ts.type == BT_CHARACTER
+         && !(formal_arg->sym->attr.allocatable
+              || formal_arg->sym->attr.pointer))
+       formal_arg->sym->ts.deferred = false;
+
       if (formal_arg->sym->ts.type == BT_CHARACTER)
        formal_arg->sym->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);

Regtests OK.

Reply via email to