Bug 25057 - default initialization and DATA statement conflict
Summary: default initialization and DATA statement conflict
Status: RESOLVED DUPLICATE of bug 32432
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on: 24978
Blocks: 31392
  Show dependency treegraph
 
Reported: 2005-11-26 17:48 UTC by Joost VandeVondele
Modified: 2007-07-04 01:25 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-01-02 05:06:57


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2005-11-26 17:48:18 UTC
using GNU Fortran 95 (GCC) 4.1.0 20051126 (prerelease)  with '-g -pedantic -std=f95', I get a bad / no diagnostic for the following invalid code:

TYPE T1
 INTEGER :: I=7
END TYPE T1
TYPE(T1), SAVE, DIMENSION(4) :: D
DATA (D(I),I=1,2) /T1(3),T1(3)/
IF (ANY(D%I.NE.(/3,3,7,7/))) write(6,*) "Never mind ..."
END
Comment 1 Francois-Xavier Coudert 2005-11-26 19:24:21 UTC
We currently have an ICE on that one:

## gfortran ##
foo.f90:0: internal compiler error: in gfc_assign_data_value, at fortran/data.c:252

## g95 ##
In file foo.f90:5

DATA (D(I),I=1,2) /T1(3),T1(3)/
       1
Error: Variable 'd' which has a default initialization cannot appear in a DATA statement at (1)
## Intel ##
## Portland ##
PGF90-W-0164-Overlapping data initializations of d (foo.f90)
  0 inform,   1 warnings,   0 severes, 0 fatal for MAIN
## Sun ##

DATA (D(I),I=1,2) /T1(3),T1(3)/
      ^
"foo.f90", Line = 5, Column = 7: ERROR: "D" must not be specified in a DATA statement.  It is typed as derived type "T1", which is default initialized.
Comment 2 Jerry DeLisle 2006-11-03 16:30:42 UTC
This is probably a duplicate of 24978.
Comment 3 Jerry DeLisle 2006-12-10 08:48:08 UTC
Just one question (A patch is on the way)

Is this legal?

TYPE T1
 INTEGER :: I
END TYPE T1
TYPE(T1), SAVE, DIMENSION(4) :: D
DATA (D(I),I=1,2) /T1(3),T1(3)/

END

Comment 4 Tobias Burnus 2006-12-10 14:24:35 UTC
> Is this legal?
> 
> TYPE T1
>  INTEGER :: I
> END TYPE T1
> TYPE(T1), SAVE, DIMENSION(4) :: D
> DATA (D(I),I=1,2) /T1(3),T1(3)/

I think it is. I didn't found anything which said otherwise and all compilers accepted it.

The relavant part of the standard, which disallows it is (Fortran 2003):

"explicit initialization (5.1) : Explicit initialization may be specified for objects of intrinsic or derived type in type declaration statements or DATA statements. An object of a derived type that specifies default initialization shall not appear in a DATA statement."
(and 3 paragraphs above "5.1.1".)
Comment 5 Tobias Burnus 2006-12-10 16:27:30 UTC
(In reply to comment #4)
> > Is this legal?
>
> I think it is. I didn't found anything which said otherwise and all compilers
> accepted it.
This is with regards to the code in comment #3.

Whereas the following is meant with regards to the code in comment #0.
> The relavant part of the standard, which disallows it is (Fortran 2003):
Comment 6 Jerry DeLisle 2007-01-02 05:06:57 UTC
Still working on it!
Comment 7 Joost VandeVondele 2007-07-03 18:27:45 UTC
this has become:
Error: 'd' at (1) already is initialized at (2)
test.f90:0: internal compiler error: Segmentation fault
Please submit a full bug report,
Comment 8 Jerry DeLisle 2007-07-04 01:25:43 UTC
This is OK now with the patch to 32432 committed today. Closing as duplicate.

*** This bug has been marked as a duplicate of 32432 ***