Bug 32928 - DATA statement with array element as initializer is rejected
Summary: DATA statement with array element as initializer is rejected
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Jerry DeLisle
Keywords: accepts-invalid, rejects-valid
Depends on:
Blocks: 32834 33056
  Show dependency treegraph
Reported: 2007-07-28 13:20 UTC by Tobias Burnus
Modified: 2007-11-28 01:15 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2007-08-26 01:55:25

Rough draft patch (534 bytes, patch)
2007-10-04 23:27 UTC, Jerry DeLisle
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-07-28 13:20:39 UTC
Found while debugging PR32315.

program chkdata
    character(len=1), parameter,dimension(4) :: string = 'A'
    character :: a
    data a /string(4)/
end program chkdata

Is rejected:
    data a /string(4)/
Error: Syntax error in DATA statement at (1)

However, g95, NAG f95, ifort, openf95 accept it.

Note that
   data a /string(5)/
should be rejected:
   First subscript (5) is greater than upper bound (4) for array STRING
Comment 1 Tobias Burnus 2007-07-28 13:29:58 UTC
The problem seems to be that in decl.c the var_element() function assumes that it only has to match a variable and not also, e.g., an array element.
Comment 2 Tobias Burnus 2007-07-28 14:00:54 UTC
R532 data-stmt-constant is scalar-constant
                        or scalar-constant-subobject
                        or signed-int-literal-constant
                        or signed-real-literal-constant
                        or null-init
                        or structure-constructor

I think this also allows for substrings.
Comment 3 Jerry DeLisle 2007-08-26 01:55:25 UTC
I am going to try this one.
Comment 4 Paul Thomas 2007-08-29 19:19:57 UTC
(In reply to comment #3)
> I am going to try this one.

This fixes it but I do not understand why it is necessary; nor have I regtested.  It's yours - I am going to tackle "spanned" pointers next, in the hope of getting it into 4.3.0

Comment 5 Jerry DeLisle 2007-10-03 04:51:11 UTC
I think the problem here is that in match_data_constant we never even attempt to match the array specification.  Using gfc_match_array_spec or gfc_match_array_ref I can successfully match and get the information.  Now I just need to figure out what to do with it. :)
Comment 6 Jerry DeLisle 2007-10-04 23:27:33 UTC
Created attachment 14298 [details]
Rough draft patch

Here is a first cut at a patch.  It does not successfully get the assignment to the integer 'a' in the test case correct.  However, the test case compiles without error and it is matching the array parameter qualifiers correctly.

I am stuck at this point, so suggestions/help appreciated.
Comment 7 Jerry DeLisle 2007-10-04 23:32:44 UTC
Note on comment #6 :  I used the following simpler test case using INTEGER rather than the original test case which uses CHARACTER.  The CHARACTER case does not compile at all.

program chkdata
    integer, parameter,dimension(4) :: string = 5
    integer :: a
    data a / string(4) /
    print *, a
end program chkdata
Comment 8 Jerry DeLisle 2007-11-28 01:02:49 UTC
Subject: Bug 32928

Author: jvdelisle
Date: Wed Nov 28 01:02:36 2007
New Revision: 130484

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130484
2007-11-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/32928
	* decl.c (match_data_constant): Use gfc_match_init_expr to match the
	array spec and set the initializer expression.


Comment 9 Jerry DeLisle 2007-11-28 01:12:44 UTC
Subject: Bug 32928

Author: jvdelisle
Date: Wed Nov 28 01:12:31 2007
New Revision: 130487

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130487
2007-11-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/32928
	* gfortran.dg/data_array_1.f90
	* gfortran.dg/data_array_2.f90
	* gfortran.dg/data_array_3.f90
	* gfortran.dg/data_array_4.f90


Comment 10 Jerry DeLisle 2007-11-28 01:15:23 UTC
Fixed on trunk.