Debian Codegraph @

gcc/testsuite/gfortran.dg/reduce_2.f90

raw
1 ! { dg-do compile }
2 !
3 ! Test argument compliance for the F2018 intrinsic REDUCE
4 !
5 ! Contributed by Paul Thomas <[email protected]>
6 !
7 class (*), allocatable :: cstar (:)
8 integer, allocatable :: i(:,:,:)
9 integer :: n(2,2)
10 Logical :: l1(4), l2(2,3), l3(2,2)
11 type :: string_t
12 character(:), allocatable :: chr(:)
13 end type
14 type(string_t) :: str
15
16 ! The ARRAY argument at (1) of REDUCE shall not be polymorphic
17 print *, reduce (cstar, add) ! { dg-error "shall not be polymorphic" }
18
19 ! OPERATION argument at %L must be a PURE function
20 print *, reduce (i, iadd) ! { dg-error "must be a PURE function" }
21 print *, reduce (i, foo) ! { dg-error "must be a PURE function" }
22
23 ! The function passed as OPERATION at (1) shall have scalar nonallocatable
24 ! nonpointer arguments and return a nonallocatable nonpointer scalar
25 print *, reduce (i, vadd) ! { dg-error "return a nonallocatable nonpointer scalar" }
26
27 ! The function passed as OPERATION at (1) shall have two arguments
28 print *, reduce (i, add_1a) ! { dg-error "shall have two arguments" }
29 print *, reduce (i, add_3a) ! { dg-error "shall have two arguments" }
30
31 !The ARRAY argument at (1) has type INTEGER(4) but the function passed as OPERATION at
32 ! (2) returns REAL(4)
33 print *, reduce (i, add_r) ! { dg-error "returns REAL" }
34
35 ! The function passed as OPERATION at (1) shall have scalar nonallocatable nonpointer
36 ! arguments and return a nonallocatable nonpointer scalar
37 print *, reduce (i, add_a) ! { dg-error "return a nonallocatable nonpointer scalar" }
38
39 ! The function passed as OPERATION at (1) shall have scalar nonallocatable nonpointer arguments and
40 ! return a nonallocatable nonpointer scalar
41 print *, reduce (i, add_array) ! { dg-error "scalar nonallocatable nonpointer arguments" }
42
43 ! The function passed as OPERATION at (1) shall not have the OPTIONAL attribute for either of the arguments
44 print *, reduce (i, add_optional) ! { dg-error "shall not have the OPTIONAL attribute" }
45
46 ! The function passed as OPERATION at (1) shall have the VALUE attribute either for none or both arguments
47 print *, reduce (i, add_one_value) ! { dg-error "VALUE attribute either for none or both arguments" }
48
49 ! The character length of the ARRAY argument at (1) and of the arguments of the OPERATION at (2)
50 ! shall be the same
51 print *, reduce ([character(4) :: 'abcd','efgh'], char_one) ! { dg-error "The character length of the ARRAY" }
52
53 ! The character length of the ARRAY argument at (1) and of the function result of the OPERATION
54 ! at (2) shall be the same
55 print *, reduce ([character(4) :: 'abcd','efgh'], char_two) ! { dg-error "function result of the OPERATION" }
56
57 ! The character length of the ARRAY argument at (1) and of the arguments of the OPERATION at
58 ! (2) shall be the same
59 print *, reduce ([character(4) :: 'abcd','efgh'], char_three) ! { dg-error "arguments of the OPERATION" }
60
61 ! The character length of the ARRAY argument at (1) and of the arguments of the OPERATION at (2)
62 ! shall be the same
63 str = reduce ([character(4) :: 'abcd','efgh'], char_one) ! { dg-error "character length of the ARRAY" }
64
65 ! The DIM argument at (1), if present, must be an integer scalar
66 print *, reduce (i, add, dim = 2.0) ! { dg-error "must be an integer scalar" }
67
68 ! The DIM argument at (1), if present, must be an integer scalar
69 print *, reduce (i, add, dim = [2]) ! { dg-error "must be an integer scalar" }
70
71 ! The MASK argument at (1), if present, must be a logical array with the same rank as ARRAY
72 print *, reduce (n, add, mask = l1) ! { dg-error "same rank as ARRAY" }
73 print *, reduce (n, add, mask = n) ! { dg-error "must be a logical array" }
74
75 ! Different shape for arguments 'ARRAY' and 'MASK' for intrinsic REDUCE at (1) on
76 ! dimension 2 (2 and 3)
77 print *, reduce (n, add, mask = l2) ! { dg-error "Different shape" }
78
79 ! The IDENTITY argument at (1), if present, must be a scalar with the same type as ARRAY
80 print *, reduce (n, add, mask = l3, identity = 1.0) ! { dg-error "same type as ARRAY" }
81 print *, reduce (n, add, mask = l3, identity = [1]) ! { dg-error "must be a scalar" }
82
83 ! MASK present at (1) without IDENTITY
84 print *, reduce (n, add, mask = l3) ! { dg-warning "without IDENTITY" }
85
86 contains
87 pure function add(i,j) result(sum_ij)
88 integer, intent(in) :: i, j
89 integer :: sum_ij
90 sum_ij = i + j
91 end function add
92 function iadd(i,j) result(sum_ij)
93 integer, intent(in) :: i, j
94 integer :: sum_ij
95 sum_ij = i + j
96 end function iadd
97 pure function vadd(i,j) result(sum_ij)
98 integer, intent(in) :: i, j
99 integer :: sum_ij(6)
100 sum_ij = i + j
101 end function vadd
102 pure function add_1a(i) result(sum_ij)
103 integer, intent(in) :: i
104 integer :: sum_ij
105 sum_ij = 0
106 end function add_1a
107 pure function add_3a(i) result(sum_ij)
108 integer, intent(in) :: i
109 integer :: sum_ij
110 sum_ij = 0
111 end function add_3a
112 pure function add_r(i, j) result(sum_ij)
113 integer, intent(in) :: i, j
114 real :: sum_ij
115 sum_ij = 0.0
116 end function add_r
117 pure function add_a(i, j) result(sum_ij)
118 integer, intent(in) :: i, j
119 integer, allocatable :: sum_ij
120 sum_ij = 0
121 end function add_a
122 pure function add_array(i, j) result(sum_ij)
123 integer, intent(in), dimension(:) :: i, j
124 integer :: sum_ij
125 sum_ij = 0
126 end function add_array
127 pure function add_optional(i, j) result(sum_ij)
128 integer, intent(in), optional :: i, j
129 integer :: sum_ij
130 sum_ij = 0
131 end function add_optional
132 pure function add_one_value(i, j) result(sum_ij)
133 integer, intent(in), value :: i
134 integer, intent(in) :: j
135 integer :: sum_ij
136 sum_ij = 0
137 end function add_one_value
138 pure function char_one(i, j) result(sum_ij)
139 character(8), intent(in) :: i, j
140 character(8) :: sum_ij
141 end function char_one
142 pure function char_two(i, j) result(sum_ij)
143 character(4), intent(in) :: i, j
144 character(8) :: sum_ij
145 end function char_two
146 pure function char_three(i, j) result(sum_ij)
147 character(8), intent(in) :: i
148 character(4), intent(in) :: j
149 character(4) :: sum_ij
150 end function char_three
151 subroutine foo
152 end subroutine foo
153 end