From d30ecc9c2bc9fc8373433302c9e351d545eed061 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Fri, 2 Oct 2015 00:53:00 +0000 Subject: [PATCH] PR fortran.67802 2015-10-01 Steven G. Kargl PR fortran.67802 * decl.c (add_init_expr_to_sym): Numeric constant for character length must be an INTEGER. 2015-10-01 Steven G. Kargl PR fortran.67802 * gfortran.dg/pr67802.f90: New test. From-SVN: r228365 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/decl.c | 7 ++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr67802.f90 | 9 +++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr67802.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 9e6f2bdbcd5..2b6a4b67f6d 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2015-10-01 Steven G. Kargl + + PR fortran.67802 + * decl.c (add_init_expr_to_sym): Numeric constant for character + length must be an INTEGER. + 2015-10-01 Steven G. Kargl PR fortran/66979 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 39c1136b68b..39e08055582 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -1439,7 +1439,12 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) /* Update initializer character length according symbol. */ else if (sym->ts.u.cl->length->expr_type == EXPR_CONSTANT) { - int len = mpz_get_si (sym->ts.u.cl->length->value.integer); + int len; + + if (!gfc_specification_expr (sym->ts.u.cl->length)) + return false; + + len = mpz_get_si (sym->ts.u.cl->length->value.integer); if (init->expr_type == EXPR_CONSTANT) gfc_set_constant_character_len (len, init, -1); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ea748b92adc..f56366a2837 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-10-01 Steven G. Kargl + + PR fortran.67802 + * gfortran.dg/pr67802.f90: New test. + 2015-10-01 Steven G. Kargl PR fortran/66979 diff --git a/gcc/testsuite/gfortran.dg/pr67802.f90 b/gcc/testsuite/gfortran.dg/pr67802.f90 new file mode 100644 index 00000000000..6095016ca09 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr67802.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/67802 +! Original code contribute by gerhard.steinmetz.fortran at t-online.de +program p + character(1.) :: c1 = ' ' ! { dg-error "must be of INTEGER" } + character(1d1) :: c2 = ' ' ! { dg-error "must be of INTEGER" } + character((0.,1.)) :: c3 = ' ' ! { dg-error "must be of INTEGER" } + character(.true.) :: c4 = ' ' ! { dg-error "must be of INTEGER" } +end program p -- 2.30.2