Fortran: Fix deferred character lengths in array constructors [PR98517].

2021-01-25  Steve Kargl  <kargl@gcc.gnu.org>

gcc/fortran
	PR fortran/98517
	* resolve.c (resolve_charlen): Check that length expression is
	present before testing for scalar/integer..

gcc/testsuite/
	PR fortran/98517
	* gfortran.dg/charlen_18.f90 : New test.
This commit is contained in:
Paul Thomas 2021-01-25 10:27:51 +00:00
parent 28229916e1
commit c6b0e33feb
2 changed files with 20 additions and 1 deletions

View file

@ -12446,7 +12446,8 @@ resolve_charlen (gfc_charlen *cl)
}
/* cl->length has been resolved. It should have an integer type. */
if (cl->length->ts.type != BT_INTEGER || cl->length->rank != 0)
if (cl->length
&& (cl->length->ts.type != BT_INTEGER || cl->length->rank != 0))
{
gfc_error ("Scalar INTEGER expression expected at %L",
&cl->length->where);

View file

@ -0,0 +1,18 @@
! { dg-do compile }
! { dg-options "-fdec-structure" }
!
! Check fix for PR98517
!
! Contributed by Eric Reischer <emr-gnu@hev.psu.edu>
!
SUBROUTINE TEST_BUG
IMPLICIT NONE
CHARACTER*(*) DEF_VAL
PARAMETER (DEF_VAL = 'ABCDEFGH')
STRUCTURE /SOME_STRUCT/
CHARACTER*64 SOME_VAR /DEF_VAL/
END STRUCTURE
END