Message ID | 20151117203442.GA92302@troutmask.apl.washington.edu |
---|---|
State | New |
Headers | show |
On 11/17/2015 12:34 PM, Steve Kargl wrote: > Here's what looks like a fairly simple patch, but it leads > to a question. Why does gfortran not try to reduce the > components in a structure constructor in general? I've > hidden the gfc_reduce_init_expr() behind a check for a > DATA statement, but I suspect gfc_reduce_init_expr() > may be useful for PARAMETER statements as well (need to > check this!). > > Anyway, the patch has been built and tested on x86_64-*-freebsd. > A slightly different patch was built and tested on i386-*-freebsd. > > OK to commit? > OK, Can't answer your question above at the moment. Jerry
Index: gcc/fortran/primary.c =================================================================== --- gcc/fortran/primary.c (revision 230497) +++ gcc/fortran/primary.c (working copy) @@ -2722,6 +2722,12 @@ gfc_match_structure_constructor (gfc_sym return MATCH_ERROR; } + /* If a structure constructor is in a DATA statement, then each entity + in the structure constructor must be a constant. Try to reduce the + expression here. */ + if (gfc_in_match_data ()) + gfc_reduce_init_expr (e); + *result = e; return MATCH_YES; } Index: gcc/testsuite/gfortran.dg/pr59910.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr59910.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr59910.f90 (working copy) @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR fortran/59910 +! +program main + implicit none + type bar + integer :: limit(1) + end type + type (bar) :: testsuite + data testsuite / bar(reshape(source=[10],shape=[1])) / +end