Bug 30792 - DATA implied-do substring allowed with -std=f95/f2003
Summary: DATA implied-do substring allowed with -std=f95/f2003
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P4 normal
Target Milestone: 6.5
Assignee: kargls
URL:
Keywords: accepts-invalid
Depends on:
Blocks: 33056
  Show dependency treegraph
 
Reported: 2007-02-14 09:38 UTC by Tobias Burnus
Modified: 2018-02-24 20:27 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-04-18 07:16:57


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-02-14 09:38:37 UTC
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
Comment 1 Tobias Burnus 2007-06-23 07:34:29 UTC
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 ' '?)
Comment 2 Tobias Burnus 2007-06-23 13:53:03 UTC
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
Comment 3 Dominique d'Humieres 2016-04-09 21:39:02 UTC
Still present at revision r234859.
Comment 4 kargls 2018-02-24 17:22:41 UTC
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
Comment 5 kargls 2018-02-24 17:51:41 UTC
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
Comment 6 kargls 2018-02-24 20:24:59 UTC
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
Comment 7 kargls 2018-02-24 20:27:33 UTC
Fixed on 6-branch, 7-branch, and trunk.