be an integer expression. The attached patch checks that a numerical constant in a CHARACTER(LEN=x) declaration is an integer. Regression tested on x86_64-*-freebsd*. OK to commit?
2015-10-01 Steven G. Kargl <ka...@gcc.gnu.org> 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 <ka...@gcc.gnu.org> PR fortran/67802 * gfortran.dg/pr67802.f90: New test. -- Steve
Index: fortran/decl.c =================================================================== --- fortran/decl.c (revision 228306) +++ fortran/decl.c (working copy) @@ -1439,7 +1439,16 @@ add_init_expr_to_sym (const char *name, /* 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 (sym->ts.u.cl->length->ts.type != BT_INTEGER) + { + gfc_error ("Expecting an scalar-int-expr at %L", + &sym->ts.u.cl->length->where); + 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); Index: testsuite/gfortran.dg/pr67802.f90 =================================================================== --- testsuite/gfortran.dg/pr67802.f90 (revision 0) +++ testsuite/gfortran.dg/pr67802.f90 (working copy) @@ -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 "Expecting an scalar-int-expr" } + character(1d1) :: c2 = ' ' ! { dg-error "Expecting an scalar-int-expr" } + character((0.,1.)) :: c3 = ' ' ! { dg-error "Expecting an scalar-int-expr" } + character(.true.) :: c4 = ' ' ! { dg-error "Expecting an scalar-int-expr" } +end program p