===================================================================
*************** gfc_get_symbol_decl (gfc_symbol * sym)
&& !(sym->attr.use_assoc && !intrinsic_array_parameter)))
gfc_defer_symbol_init (sym);
+ if (sym->ts.type == BT_CHARACTER
+ && sym->attr.allocatable
+ && !sym->attr.dimension
+ && sym->ts.u.cl && sym->ts.u.cl->length
+ && sym->ts.u.cl->length->expr_type == EXPR_VARIABLE)
+ gfc_defer_symbol_init (sym);
+
/* Associate names can use the hidden string length variable
of their associated target. */
if (sym->ts.type == BT_CHARACTER
*************** gfc_trans_deferred_vars (gfc_symbol * pr
gfc_set_backend_locus (&sym->declared_at);
gfc_start_block (&init);
+ if (sym->ts.type == BT_CHARACTER
+ && sym->attr.allocatable
+ && !sym->attr.dimension
+ && sym->ts.u.cl && sym->ts.u.cl->length
+ && sym->ts.u.cl->length->expr_type == EXPR_VARIABLE)
+ gfc_conv_string_length (sym->ts.u.cl, NULL, &init);
+
if (!sym->attr.pointer)
{
/* Nullify and automatic deallocation of allocatable
===================================================================
***************
+ ! { dg-do run }
+ !
+ ! Test the fix for PR64120 in which the initialisation of the
+ ! string length of 's' was not being done.
+ !
+ ! Contributed by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
+ !
+ call g(1)
+ call g(2)
+ contains
+ subroutine g(x)
+ integer :: x
+ character(len=x), allocatable :: s
+ allocate(s)
+ if (len(s) .ne. x) stop x
+ end subroutine
+ end