From c6b0e33febbf73abfcc2bb0e28f0b62afe3b0f2a Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Mon, 25 Jan 2021 10:27:51 +0000 Subject: [PATCH] Fortran: Fix deferred character lengths in array constructors [PR98517]. 2021-01-25 Steve Kargl 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. --- gcc/fortran/resolve.c | 3 ++- gcc/testsuite/gfortran.dg/charlen_18.f90 | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/charlen_18.f90 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index c075d0fa0c4..11b5dbc7a03 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -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); diff --git a/gcc/testsuite/gfortran.dg/charlen_18.f90 b/gcc/testsuite/gfortran.dg/charlen_18.f90 new file mode 100644 index 00000000000..5ad287448b4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/charlen_18.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! { dg-options "-fdec-structure" } +! +! Check fix for PR98517 +! +! Contributed by Eric Reischer +! + SUBROUTINE TEST_BUG + IMPLICIT NONE + + CHARACTER*(*) DEF_VAL + PARAMETER (DEF_VAL = 'ABCDEFGH') + + STRUCTURE /SOME_STRUCT/ + CHARACTER*64 SOME_VAR /DEF_VAL/ + END STRUCTURE + + END -- 2.30.2