2 ! { dg-options "-std=f95 -fmax-errors=0" }
4 ! Testcases from PR fortran/24978
7 SUBROUTINE data_init_scalar_invalid()
10 data a
/ 1 / ! { dg-error "re-initialization" }
13 data b
/ 1 / ! { dg-error "re-initialization" }
16 SUBROUTINE data_init_array_invalid()
17 ! initialize (at least) one element, re-initialize full array
20 data a
/ 3*1 / ! { dg-error "re-initialization" }
22 ! initialize (at least) one element, re-initialize subsection including the element
25 data b(1:2) / 2*1 / ! { dg-error "re-initialization" }
27 ! initialize subsection, re-initialize (intersecting) subsection
30 data c(2:3) / 1,1 / ! { dg-error "re-initialization" }
32 ! initialize subsection, re-initialize full array
35 data d
/ 2*2, 3 / ! { dg-error "re-initialization" }
37 ! full array initializer, re-initialize (at least) one element
40 data e(2) / 2 / ! { dg-error "re-initialization" }
42 integer :: f(3) = 0 ! { dg-error "already is initialized" }
43 data f(2) / 1 / ! { dg-error "already is initialized" }
45 ! full array initializer, re-initialize subsection
48 data g(1:2) / 2*2 / ! { dg-error "re-initialization" }
50 integer :: h(3) = 1 ! { dg-error "already is initialized" }
51 data h(2:3) / 2*2 / ! { dg-error "already is initialized" }
53 ! full array initializer, re-initialize full array
56 data i
/ 2,2,2 / ! { dg-error "re-initialization" }
58 integer :: j(3) = 1 ! { dg-error "already is initialized" }
59 data j
/ 3*2 / ! { dg-error "already is initialized" }
62 SUBROUTINE data_init_matrix_invalid()
63 ! initialize (at least) one element, re-initialize full matrix
66 data a
/ 9*2 / ! { dg-error "re-initialization" }
68 ! initialize (at least) one element, re-initialize subsection
71 data b(2,:) / 3*2 / ! { dg-error "re-initialization" }
73 ! initialize subsection, re-initialize (intersecting) subsection
75 data c(3,:) / 3*1 /, c(:,3) / 3*2 / ! { dg-error "re-initialization" }
77 ! initialize subsection, re-initialize full array
80 data d
/ 9*4 / ! { dg-error "re-initialization" }
82 ! full array initializer, re-initialize (at least) one element
85 data e(2,3) / 2 / ! { dg-error "re-initialization" }
87 integer :: f(3,3) = 1 ! { dg-error "already is initialized" }
88 data f(3,2) / 2 / ! { dg-error "already is initialized" }
90 ! full array initializer, re-initialize subsection
93 data g(2:3,2:3) / 2, 2*3, 4 / ! { dg-error "re-initialization" }
95 integer :: h(3,3) = 1 ! { dg-error "already is initialized" }
96 data h(2:3,2:3) / 2, 2*3, 4 / ! { dg-error "already is initialized" }
98 ! full array initializer, re-initialize full array
100 data i
/ 3*1, 3*2, 3*3 /
101 data i
/ 9 * 1 / ! { dg-error "re-initialization" }
103 integer :: j(3,3) = 0 ! { dg-error "already is initialized" }
104 data j
/ 9 * 1 / ! { dg-error "already is initialized" }
107 SUBROUTINE data_init_misc_invalid()
108 ! wrong number of dimensions
110 data a(1,1) / 1 / ! { dg-error "Rank mismatch" }
112 ! index out-of-bounds, direct access
114 data b(-2) / 1 / ! { dg-error "below array lower bound" }
115 ! { dg-warning "is out of bounds" "" { target *-*-* } .-1 }
116 ! index out-of-bounds, implied do-loop (PR32315)
118 character(len
=20), dimension(4) :: string
119 data (string(i
), i
= 1, 5) / 'A', 'B', 'C', 'D', 'E' / ! { dg-error "above array upper bound" }