Fortran: Set the length of an allocatable character

PR fortran/113883

gcc/fortran/ChangeLog:

	* trans-array.cc (gfc_trans_deferred_array): Set length to zero,
	avoiding extraneous diagnostics.

gcc/testsuite/ChangeLog:

	* gfortran.dg/allocatable_length.f90: New test.
This commit is contained in:
Steve Kargl 2024-02-12 20:41:02 -08:00 committed by Jerry DeLisle
parent b753ef8f0c
commit 6caec7d9ec
2 changed files with 12 additions and 0 deletions

View file

@ -11531,6 +11531,9 @@ gfc_trans_deferred_array (gfc_symbol * sym, gfc_wrapped_block * block)
if (sym->ts.type == BT_CHARACTER
&& !INTEGER_CST_P (sym->ts.u.cl->backend_decl))
{
if (sym->ts.deferred && !sym->ts.u.cl->length)
gfc_add_modify (&init, sym->ts.u.cl->backend_decl,
build_zero_cst (TREE_TYPE (sym->ts.u.cl->backend_decl)));
gfc_conv_string_length (sym->ts.u.cl, NULL, &init);
gfc_trans_vla_type_sizes (sym, &init);

View file

@ -0,0 +1,9 @@
! { dg-do compile }
! { dg-options "-Werror -Wall" }
module foo
contains
subroutine bar
character(len=:), allocatable :: s(:)
call bah(s)
end subroutine bar
end module foo