From b1be0054be0149ad735e662912e01ebd258cea49 Mon Sep 17 00:00:00 2001 From: Jerry DeLisle Date: Sat, 22 Jun 2019 19:58:47 +0000 Subject: [PATCH] re PR fortran/89782 (Can do an internal READ of a character array when it is a parameter, but not a scalar character parameter) 2019-06-22 Jerry DeLisle PR fortran/89782 * io.c (gfc_resolve_dt): Check that internal units are not character PARAMETER. * gfortran.dg/io_constraints.f90: New test. From-SVN: r272594 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/io.c | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/io_constraints_14.f90 | 13 +++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/io_constraints_14.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 42892276dbd..6489a047280 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-06-22 Jerry DeLisle + + PR fortran/89782 + * io.c (gfc_resolve_dt): Check that internal units are not + character PARAMETER. + 2019-06-21 Steven G. Kargl PR fortran/67884 diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c index 425c2b86899..cd21c6bcf82 100644 --- a/gcc/fortran/io.c +++ b/gcc/fortran/io.c @@ -3328,6 +3328,14 @@ gfc_resolve_dt (gfc_dt *dt, locus *loc) return false; } + if (e->symtree && e->symtree->n.sym->attr.flavor == FL_PARAMETER + && e->ts.type == BT_CHARACTER) + { + gfc_error ("UNIT specification at %L must " + "not be a character PARAMETER", &e->where); + return false; + } + if (gfc_resolve_expr (e) && (e->ts.type != BT_INTEGER && (e->ts.type != BT_CHARACTER || e->expr_type != EXPR_VARIABLE))) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e4f4cf86285..edd706420ba 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-06-22 Jerry DeLisle + + PR fortran/89782 + * gfortran.dg/io_constraints.f90: New test. + 2019-06-22 Iain Sandoe * gcc.target/powerpc/pr64205.c: Require effective target dfp. diff --git a/gcc/testsuite/gfortran.dg/io_constraints_14.f90 b/gcc/testsuite/gfortran.dg/io_constraints_14.f90 new file mode 100644 index 00000000000..e5b62b1f70d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/io_constraints_14.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +program pr89782 + character(len=*),parameter :: VALUES(*)=[character(len=10) :: 'NaN','NAN','nan','Inf','INF','inf','Infinity'] + character(len=*),parameter :: VALUE='NaN' + real(4) :: var + do i=1,size(VALUES) + read(VALUES(i),*) float ! { dg-error "character PARAMETER" } + write(VALUES(i),*)float ! { dg-error "character PARAMETER" } + enddo + read(var,*)float ! { dg-error "INTEGER expression or a CHARACTER" } + read(VALUE,*)float ! { dg-error "character PARAMETER" } + write(VALUE,*)float ! { dg-error "character PARAMETER" } +end program pr89782 -- 2.30.2