Skip to content

Commit 6caec7d

Browse files
Steve KarglJerry DeLisle
authored andcommitted
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.
1 parent b753ef8 commit 6caec7d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

gcc/fortran/trans-array.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11531,6 +11531,9 @@ gfc_trans_deferred_array (gfc_symbol * sym, gfc_wrapped_block * block)
1153111531
if (sym->ts.type == BT_CHARACTER
1153211532
&& !INTEGER_CST_P (sym->ts.u.cl->backend_decl))
1153311533
{
11534+
if (sym->ts.deferred && !sym->ts.u.cl->length)
11535+
gfc_add_modify (&init, sym->ts.u.cl->backend_decl,
11536+
build_zero_cst (TREE_TYPE (sym->ts.u.cl->backend_decl)));
1153411537
gfc_conv_string_length (sym->ts.u.cl, NULL, &init);
1153511538
gfc_trans_vla_type_sizes (sym, &init);
1153611539

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
! { dg-do compile }
2+
! { dg-options "-Werror -Wall" }
3+
module foo
4+
contains
5+
subroutine bar
6+
character(len=:), allocatable :: s(:)
7+
call bah(s)
8+
end subroutine bar
9+
end module foo

0 commit comments

Comments
 (0)