diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index aedec2cf78e..a4897da6434 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2005-07-14 Feng Wang + Steven G. Kargl + + * array.c (resolve_character_array_constructor): Allocate gfc_charlen + for the array and attach to namespace list for automatic deallocation. + 2005-07-13 Andreas Schwab * Make-lang.in (fortran/dependency.o): Depend on diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index dc65644f5e6..72b92a8368b 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -1529,7 +1529,14 @@ resolve_character_array_constructor (gfc_expr * expr) max_length = -1; - if (expr->ts.cl == NULL || expr->ts.cl->length == NULL) + if (expr->ts.cl == NULL) + { + expr->ts.cl = gfc_get_charlen (); + expr->ts.cl->next = gfc_current_ns->cl_list; + gfc_current_ns->cl_list = expr->ts.cl; + } + + if (expr->ts.cl->length == NULL) { /* Find the maximum length of the elements. Do nothing for variable array constructor. */ @@ -1542,8 +1549,6 @@ resolve_character_array_constructor (gfc_expr * expr) if (max_length != -1) { /* Update the character length of the array constructor. */ - if (expr->ts.cl == NULL) - expr->ts.cl = gfc_get_charlen (); expr->ts.cl->length = gfc_int_expr (max_length); /* Update the element constructors. */ for (p = expr->value.constructor; p; p = p->next) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e4682e59a91..1c94063bc1b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-07-14 Steven G. Kargl + + * gfortran.dg/char_array_constructor.f90: New test. + 2005-07-13 Paul Thomas * gfortran.dg/past_eor.f90: New. diff --git a/gcc/testsuite/gfortran.dg/char_array_constructor.f90 b/gcc/testsuite/gfortran.dg/char_array_constructor.f90 new file mode 100644 index 00000000000..0cb4d38bf03 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_array_constructor.f90 @@ -0,0 +1,15 @@ +! { dg-do run } +module z + integer :: i + character(6) :: a(2) = (/ ('main ' , i = 1, 2) /) + character(6) :: b(2) = (/ 'abcd ' , 'efghij' /) +end module + +program y + use z + if (a(1) /= 'main ') call abort + if (a(2) /= 'main ') call abort + if (b(1) /= 'abcd ') call abort + if (b(2) /= 'efghij') call abort +end program y +