The attached patch restores 3 lines of code removed in my
fix for PR fortran/65429. The code now checks for a NULL
character length in the typespec. If it is indeed NULL,
gfortran will look for a valid constructor to use (ie.,
the 3 lines of code). It is somewhat surprising that
it took 6 months for this bug to appear. Patch tested
on x86_64-*-freebsd. OK to commit?
2015-10-29 Steven G. Kargl
PR fortran/68154
* decl.c (add_init_expr_to_sym): if the char length in the typespec
is NULL, check for and use the constructor.
2015-10-29 Steven G. Kargl
PR fortran/68154
*gfortran.dg/pr68154.f90
--
Steve
Index: gcc/fortran/decl.c
===
--- gcc/fortran/decl.c (revision 229542)
+++ gcc/fortran/decl.c (working copy)
@@ -1461,7 +1461,16 @@ add_init_expr_to_sym (const char *name,
}
else if (init->expr_type == EXPR_ARRAY)
{
- clen = mpz_get_si (init->ts.u.cl->length->value.integer);
+ if (init->ts.u.cl)
+ clen = mpz_get_si (init->ts.u.cl->length->value.integer);
+ else if (init->value.constructor)
+ {
+ gfc_constructor *c;
+ c = gfc_constructor_first (init->value.constructor);
+ clen = c->expr->value.character.length;
+ }
+ else
+ clen = 1;
sym->ts.u.cl->length
= gfc_get_int_expr (gfc_default_integer_kind,
NULL, clen);
Index: gcc/testsuite/gfortran.dg/pr68154.f90
===
--- gcc/testsuite/gfortran.dg/pr68154.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/pr68154.f90 (working copy)
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/68154
+! Original code contributed by Gerhard Steinmetz
+! gerhard dot steinmetz dot fortran at t-online dot de
+program p
+ character(1), parameter :: x1(2) = 'a'
+ character(*), parameter :: x2(2) = x1
+ character(*), parameter :: x3(*) = x1
+end