aboutsummaryrefslogtreecommitdiff
blob: 7cfa5ac1f17c8682c66dd877856cdfa9a0dc3943 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
! RUN: %S/test_errors.sh %s %t %flang_fc1
!Testing data constraints : C876, C877
module m
  integer :: first
  contains
    subroutine h
      integer a,b
      !C876
      !ERROR: Host-associated object 'first' must not be initialized in a DATA statement
      DATA first /1/
    end subroutine

    function g(i)
      integer ::i
      g = i *1024
    end

    function f(i)
      integer ::i
      integer ::result
      integer, allocatable :: a
      integer :: b(i)
      character(len=i), pointer:: charPtr
      character(len=i), allocatable:: charAlloc
      !C876
      !ERROR: Dummy argument 'i' must not be initialized in a DATA statement
      DATA i /1/
      !C876
      !ERROR: Function result 'f' must not be initialized in a DATA statement
      DATA f /1/
      !C876
      !ERROR: Procedure 'g' must not be initialized in a DATA statement
      DATA g /1/
      !C876
      !ERROR: Allocatable 'a' must not be initialized in a DATA statement
      DATA a /1/
      !C876
      !ERROR: Automatic variable 'b' must not be initialized in a DATA statement
      DATA b(0) /1/
      !C876
      !Ok: As charPtr is a pointer, it is not an automatic object
      DATA charPtr / NULL() /
      !C876
      !ERROR: Allocatable 'charalloc' must not be initialized in a DATA statement
      DATA charAlloc / 'abc' /
      f = i *1024
    end

    subroutine CheckObject(i)
      type specialNumbers
        integer one
        integer numbers(5)
        type(specialNumbers), pointer :: headOfTheList
        integer, pointer, dimension(:) :: ptoarray
        character, pointer, dimension(:) :: ptochar
      end type
      type large
        integer, allocatable :: allocVal
        integer, allocatable :: elt(:)
        integer val
        type(specialNumbers) numsArray(5)
      end type
      type(large) largeNumber
      type(large), allocatable :: allocatableLarge
      type(large) :: largeNumberArray(i)
      type(large) :: largeArray(5)
      character :: name(i)
      !C877
      !ERROR: Default-initialized 'largenumber' must not be initialized in a DATA statement
      DATA(largeNumber % numsArray(j) % headOfTheList, j = 1, 10) / 10 * NULL() /
      !C877
      !ERROR: Data object must not contain pointer 'headofthelist' as a non-rightmost part
      DATA(largeNumber % numsArray(j) % headOfTheList % one, j = 1, 10) / 10 * 1 /
      !C877
      !ERROR: Rightmost data object pointer 'ptoarray' must not be subscripted
      DATA(largeNumber % numsArray(j) % ptoarray(1), j = 1, 10) / 10 * 1 /
      !C877
      !ERROR: Rightmost data object pointer 'ptochar' must not be subscripted
      DATA largeNumber % numsArray(0) % ptochar(1:2) / 'ab' /
      !C876
      !ERROR: Default-initialized 'largenumber' must not be initialized in a DATA statement
      DATA(largeNumber % elt(j) , j = 1, 10) / 10 * 1/
      !C876
      !ERROR: Default-initialized 'largearray' must not be initialized in a DATA statement
      DATA(largeArray(j) % allocVal , j = 1, 10) / 10 * 1/
      !C876
      !ERROR: Allocatable 'allocatablelarge' must not be initialized in a DATA statement
      DATA allocatableLarge % val / 1 /
      !C876
      !ERROR: Automatic variable 'largenumberarray' must not be initialized in a DATA statement
      DATA(largeNumberArray(j) % val, j = 1, 10) / 10 * NULL() /
      !C876
      !ERROR: Automatic variable 'name' must not be initialized in a DATA statement
      DATA name( : 2) / 'Ancd' /
    end
  end

  block data foo
          integer :: a,b
          common /c/ a,b
          !C876
          !OK: Correct use
          DATA a /1/
  end block data

  module m2
    integer m2_i
    type newType
      integer number
    end type
    type(newType) m2_number1
    contains

    subroutine checkDerivedType(m2_number)
      type(newType) m2_number
      type(newType) m2_number3
      !C876
      !ERROR: Dummy argument 'm2_number' must not be initialized in a DATA statement
      DATA m2_number%number /1/
      !C876
      !ERROR: Host-associated object 'm2_number1' must not be initialized in a DATA statement
      DATA m2_number1%number /1/
      !C876
      !OK: m2_number3 is not associated through use association
      DATA m2_number3%number /1/
    end
  end

  program new
    use m2
    integer a
    real    b,c
    type seqType
      sequence
      integer number
    end type
    type(SeqType) num
    COMMON b,a,c,num
    type(newType) m2_number2
    !C876
    !ERROR: Blank COMMON object 'b' must not be initialized in a DATA statement
    DATA b /1/
    !C876
    !ERROR: USE-associated object 'm2_i' must not be initialized in a DATA statement
    DATA m2_i /1/
    !C876
    !ERROR: USE-associated object 'm2_number1' must not be initialized in a DATA statement
    DATA m2_number1%number /1/
    !C876
    !OK: m2_number2 is not associated through use association
    DATA m2_number2%number /1/
    !C876
    !ERROR: Blank COMMON object 'num' must not be initialized in a DATA statement
    DATA num%number /1/
  end program