The following mini program gives an error in other compilers, but not in gfortran, we should check whether we need to give an error as well. Cf. http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/1cb58e9fed576fbe --------------------------- CHARACTER string*1025 INTEGER i DATA (string(i:i),i=1,1025)/1025*'?'/ end --------------------------- $ g95 foo1.f90 In file foo1.f90:3 DATA (string(i:i),i=1,1025)/1025*'?'/ 1 Error: DATA element inside iterator at (1) must be an array element or a scalar structure component $ f95 foo1.f90 # NAG f95 foo1.f90 Error: foo1.f90, line 3: Substring in data-implied-do detected at )@, $ sunf95 foo1.f90 DATA (string(i:i),i=1,1025)/1025*'?'/ ^ "foo1.f90", Line = 3, Column = 13: ERROR: A DATA implied-DO target must be an array element or scalar structure component reference. (It is accepted with "ifort -stand f95 -warn all".) At a glance, I cannot find this restriction in the Fortran 2003 standard. We should also check the corrigenda and F95+corrigenda. http://gcc.gnu.org/wiki/GFortranStandards
R527 data-implied-do is ( data-i-do-object-list , data-i-do-variable = scalar-int-expr, scalar-int-expr [ , scalar-int-expr ] ) R528 data-i-do-object is array-element or scalar-structure-component or data-implied-do which does not include substrings. Related: character(len=20) :: a = 'xyz' data a(1:3)/'abc'/ -> Overlapping storage initializations (otherwise valid) Should be detected with -std=f95. character(len=3) :: b integer :: i data (b(i:i),i=1,3)/3*'x'/ data (b(i:i),i=2,2)/'y'/ print *, b -> Overlapping storage initializations (substrings are also not standard conform) -> Should this be detected or ignored? (This is not detected by ifort either; both ifort and gfortran print 'xxx'; if one reverses the data order, both print 'xyx'.) Observation (should be ok either way): character(len=20) :: a data a(1:3)/'abc'/ print '(":",a,":")', a gfortran prints: :abc : g95, NAG f95, ifort print: :abc: (for "a = 'abc'" they have the same as gfortran. -> preinitialized by \0 vs. by ' '?)
Also the following is not allowed: data (string,i=1,1)/'hello'/ or data (string,i=1,2)/'hello','foo'/ For the second, ifort -stand f95: Warning: Overlapping storage initializations encountered with STRING For both: - NAG f95: syntax error - g95: Error: DATA element inside iterator must be an array element or a scalar structure component
Still present at revision r234859.
Author: kargl Date: Sat Feb 24 17:22:10 2018 New Revision: 257962 URL: https://gcc.gnu.org/viewcvs?rev=257962&root=gcc&view=rev Log: 2018-02-24 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/30792 * decl.c (gfc_match_data): Check for invalid substring in data-implied-do 2018-02-24 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/30792 * gfortran.dg/data_substring.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/data_substring.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/decl.c trunk/gcc/testsuite/ChangeLog
Author: kargl Date: Sat Feb 24 17:51:09 2018 New Revision: 257963 URL: https://gcc.gnu.org/viewcvs?rev=257963&root=gcc&view=rev Log: 2018-02-24 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/30792 * decl.c (gfc_match_data): Check for invalid substring in data-implied-do 2018-02-24 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/30792 * gfortran.dg/data_substring.f90: New test. Added: branches/gcc-7-branch/gcc/testsuite/gfortran.dg/data_substring.f90 Modified: branches/gcc-7-branch/gcc/fortran/ChangeLog branches/gcc-7-branch/gcc/fortran/decl.c branches/gcc-7-branch/gcc/testsuite/ChangeLog
Author: kargl Date: Sat Feb 24 20:24:27 2018 New Revision: 257964 URL: https://gcc.gnu.org/viewcvs?rev=257964&root=gcc&view=rev Log: 2018-02-24 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/30792 * decl.c (gfc_match_data): Check for invalid substring in data-implied-do 2018-02-24 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/30792 * gfortran.dg/data_substring.f90: New test. Added: branches/gcc-6-branch/gcc/testsuite/gfortran.dg/data_substring.f90 Modified: branches/gcc-6-branch/gcc/fortran/ChangeLog branches/gcc-6-branch/gcc/fortran/decl.c branches/gcc-6-branch/gcc/testsuite/ChangeLog
Fixed on 6-branch, 7-branch, and trunk.