case01.f90
4.54 KB
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
156
157
158
159
160
161
162
163
164
165
! RUN: %S/test_errors.sh %s %t %f18
! Test SELECT CASE Constraints: C1145, C1146, C1147, C1148, C1149
program selectCaseProg
implicit none
! local variable declaration
character :: grade1 = 'B'
integer :: grade2 = 3
logical :: grade3 = .false.
real :: grade4 = 2.0
character (len = 10) :: name = 'test'
logical, parameter :: grade5 = .false.
CHARACTER(KIND=1), parameter :: ASCII_parm1 = 'a', ASCII_parm2='b'
CHARACTER(KIND=2), parameter :: UCS16_parm = 'c'
CHARACTER(KIND=4), parameter :: UCS32_parm ='d'
type scores
integer :: val
end type
type (scores) :: score = scores(25)
type (scores), parameter :: score_val = scores(50)
! Valid Cases
select case (grade1)
case ('A')
case ('B')
case ('C')
case default
end select
select case (grade2)
case (1)
case (2)
case (3)
case default
end select
select case (grade3)
case (.true.)
case (.false.)
end select
select case (name)
case default
case ('now')
case ('test')
end select
! C1145
!ERROR: SELECT CASE expression must be integer, logical, or character
select case (grade4)
case (1.0)
case (2.0)
case (3.0)
case default
end select
!ERROR: SELECT CASE expression must be integer, logical, or character
select case (score)
case (score_val)
case (scores(100))
end select
! C1146
select case (grade3)
case default
case (.true.)
!ERROR: CASE DEFAULT conflicts with previous cases
case default
end select
! C1147
select case (grade2)
!ERROR: CASE value has type 'CHARACTER(1)' which is not compatible with the SELECT CASE expression's type 'INTEGER(4)'
case (:'Z')
case default
end select
select case (grade1)
!ERROR: CASE value has type 'INTEGER(4)' which is not compatible with the SELECT CASE expression's type 'CHARACTER(KIND=1,LEN=1_8)'
case (:1)
case default
end select
select case (grade3)
case default
case (.true.)
!ERROR: CASE value has type 'INTEGER(4)' which is not compatible with the SELECT CASE expression's type 'LOGICAL(4)'
case (3)
end select
select case (grade2)
case default
case (2 :)
!ERROR: CASE value has type 'LOGICAL(4)' which is not compatible with the SELECT CASE expression's type 'INTEGER(4)'
case (.true. :)
!ERROR: CASE value has type 'REAL(4)' which is not compatible with the SELECT CASE expression's type 'INTEGER(4)'
case (1.0)
!ERROR: CASE value has type 'CHARACTER(1)' which is not compatible with the SELECT CASE expression's type 'INTEGER(4)'
case ('wow')
end select
select case (ASCII_parm1)
case (ASCII_parm2)
!ERROR: CASE value has type 'CHARACTER(4)' which is not compatible with the SELECT CASE expression's type 'CHARACTER(1)'
case (UCS32_parm)
!ERROR: CASE value has type 'CHARACTER(2)' which is not compatible with the SELECT CASE expression's type 'CHARACTER(1)'
case (UCS16_parm)
!ERROR: CASE value has type 'CHARACTER(4)' which is not compatible with the SELECT CASE expression's type 'CHARACTER(1)'
case (4_"ucs-32")
!ERROR: CASE value has type 'CHARACTER(2)' which is not compatible with the SELECT CASE expression's type 'CHARACTER(1)'
case (2_"ucs-16")
case default
end select
! C1148
select case (grade3)
case default
!ERROR: CASE range is not allowed for LOGICAL
case (.true. :)
end select
! C1149
select case (grade3)
case (.true.)
case (.false.)
!ERROR: CASE (.true._1) conflicts with previous cases
case (.true.)
!ERROR: CASE (.false._1) conflicts with previous cases
case (grade5)
end select
select case (grade2)
case (51:50) ! warning
case (100:)
case (:30)
case (40)
case (90)
case (91:99)
!ERROR: CASE (81_16:90_16) conflicts with previous cases
case (81:90)
!ERROR: CASE (:80_16) conflicts with previous cases
case (:80)
!ERROR: CASE (200_16) conflicts with previous cases
case (200)
case default
end select
select case (name)
case ('hello')
case ('hey')
!ERROR: CASE (:"hh") conflicts with previous cases
case (:'hh')
!ERROR: CASE (:"hd") conflicts with previous cases
case (:'hd')
case ( 'hu':)
case ('hi':'ho')
!ERROR: CASE ("hj") conflicts with previous cases
case ('hj')
!ERROR: CASE ("ha") conflicts with previous cases
case ('ha')
!ERROR: CASE ("hz") conflicts with previous cases
case ('hz')
case default
end select
end program