annotate gcc/testsuite/ada/acats/tests/c3/c330002.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- C330002.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that if a subtype indication of a variable object defines an
kono
parents:
diff changeset
28 -- indefinite subtype, then there is an initialization expression.
kono
parents:
diff changeset
29 -- Check that the object remains so constrained throughout its lifetime.
kono
parents:
diff changeset
30 -- Check for cases of tagged record, arrays and generic formal type.
kono
parents:
diff changeset
31 --
kono
parents:
diff changeset
32 -- TEST DESCRIPTION:
kono
parents:
diff changeset
33 -- An indefinite subtype is either:
kono
parents:
diff changeset
34 -- a) An unconstrained array subtype.
kono
parents:
diff changeset
35 -- b) A subtype with unknown discriminants (this includes class-wide
kono
parents:
diff changeset
36 -- types).
kono
parents:
diff changeset
37 -- c) A subtype with unconstrained discriminants without defaults.
kono
parents:
diff changeset
38 --
kono
parents:
diff changeset
39 -- Declare tagged types with unconstrained discriminants without
kono
parents:
diff changeset
40 -- defaults. Declare an unconstrained array. Declare a generic formal
kono
parents:
diff changeset
41 -- type with an unknown discriminant and a formal object of this type.
kono
parents:
diff changeset
42 -- In the generic package, declare an object of the formal type using
kono
parents:
diff changeset
43 -- the formal object as its initial value. In the main program,
kono
parents:
diff changeset
44 -- declare objects of tagged types. Instantiate the generic package.
kono
parents:
diff changeset
45 -- The test checks that Constraint_Error is raised if an attempt is
kono
parents:
diff changeset
46 -- made to change bounds as well as discriminants of the objects of the
kono
parents:
diff changeset
47 -- indefinite subtypes.
kono
parents:
diff changeset
48 --
kono
parents:
diff changeset
49 --
kono
parents:
diff changeset
50 -- CHANGE HISTORY:
kono
parents:
diff changeset
51 -- 01 Nov 95 SAIC Initial prerelease version.
kono
parents:
diff changeset
52 -- 27 Jul 96 SAIC Modified test description & Report.Test. Added
kono
parents:
diff changeset
53 -- code to prevent dead variable optimization.
kono
parents:
diff changeset
54 --
kono
parents:
diff changeset
55 --!
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 package C330002_0 is
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 subtype Small_Num is Integer range 1 .. 20;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -- Types with unconstrained discriminants without defaults.
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 type Tag_Type (Disc : Small_Num) is tagged
kono
parents:
diff changeset
64 record
kono
parents:
diff changeset
65 S : String (1 .. Disc);
kono
parents:
diff changeset
66 end record;
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 function Tag_Value return Tag_Type;
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 procedure Assign_Tag (A : out Tag_Type);
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 procedure Avoid_Optimization_and_Fail (P : Tag_Type; Msg : String);
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 ---------------------------------------------------------------------
kono
parents:
diff changeset
75 -- An unconstrained array type.
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 type Array_Type is array (Positive range <>) of Integer;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 function Array_Value return Array_Type;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 procedure Assign_Array (A : out Array_Type);
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 ---------------------------------------------------------------------
kono
parents:
diff changeset
84 generic
kono
parents:
diff changeset
85 -- Type with an unknown discriminant.
kono
parents:
diff changeset
86 type Formal_Type (<>) is private;
kono
parents:
diff changeset
87 FT_Obj : Formal_Type;
kono
parents:
diff changeset
88 package Gen is
kono
parents:
diff changeset
89 Gen_Obj : Formal_Type := FT_Obj;
kono
parents:
diff changeset
90 end Gen;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 end C330002_0;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 --==================================================================--
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 with Report;
kono
parents:
diff changeset
97 package body C330002_0 is
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 procedure Assign_Tag (A : out Tag_Type) is
kono
parents:
diff changeset
100 begin
kono
parents:
diff changeset
101 A := (3, "Bye");
kono
parents:
diff changeset
102 end Assign_Tag;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 ----------------------------------------------------------------------
kono
parents:
diff changeset
105 procedure Avoid_Optimization_and_Fail (P : Tag_Type; Msg : String) is
kono
parents:
diff changeset
106 Default : Tag_Type := (1, "!"); -- Unique value.
kono
parents:
diff changeset
107 begin
kono
parents:
diff changeset
108 if P = Default then -- Both If branches can't do the same thing.
kono
parents:
diff changeset
109 Report.Failed (Msg & ": Constraint_Error not raised");
kono
parents:
diff changeset
110 else -- Subtests should always select this path.
kono
parents:
diff changeset
111 Report.Failed ("Constraint_Error not raised " & Msg);
kono
parents:
diff changeset
112 end if;
kono
parents:
diff changeset
113 end Avoid_Optimization_and_Fail;
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 ----------------------------------------------------------------------
kono
parents:
diff changeset
116 function Tag_Value return Tag_Type is
kono
parents:
diff changeset
117 TO : Tag_Type := (4 , "ACVC");
kono
parents:
diff changeset
118 begin
kono
parents:
diff changeset
119 return TO;
kono
parents:
diff changeset
120 end Tag_Value;
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 ----------------------------------------------------------------------
kono
parents:
diff changeset
123 function Array_Value return Array_Type is
kono
parents:
diff changeset
124 IA : Array_Type := (20, 31);
kono
parents:
diff changeset
125 begin
kono
parents:
diff changeset
126 return IA;
kono
parents:
diff changeset
127 end Array_Value;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 ----------------------------------------------------------------------
kono
parents:
diff changeset
130 procedure Assign_Array (A : out Array_Type) is
kono
parents:
diff changeset
131 begin
kono
parents:
diff changeset
132 A := (84, 36);
kono
parents:
diff changeset
133 end Assign_Array;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 end C330002_0;
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 --==================================================================--
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 with Report;
kono
parents:
diff changeset
140 with C330002_0;
kono
parents:
diff changeset
141 use C330002_0;
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 procedure C330002 is
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 begin
kono
parents:
diff changeset
146 Report.Test ("C330002", "Check that if a subtype indication of a " &
kono
parents:
diff changeset
147 "variable object defines an indefinite subtype, then " &
kono
parents:
diff changeset
148 "there is an initialization expression. Check that " &
kono
parents:
diff changeset
149 "the object remains so constrained throughout its " &
kono
parents:
diff changeset
150 "lifetime. Check that Constraint_Error is raised " &
kono
parents:
diff changeset
151 "if an attempt is made to change bounds as well as " &
kono
parents:
diff changeset
152 "discriminants of the objects of the indefinite " &
kono
parents:
diff changeset
153 "subtypes. Check for cases of tagged record and generic " &
kono
parents:
diff changeset
154 "formal types");
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 TagObj_Block:
kono
parents:
diff changeset
157 declare
kono
parents:
diff changeset
158 TObj_ByAgg : Tag_Type := (5, "Hello"); -- Initial assignment is
kono
parents:
diff changeset
159 -- aggregate.
kono
parents:
diff changeset
160 TObj_ByObj : Tag_Type := TObj_ByAgg; -- Initial assignment is
kono
parents:
diff changeset
161 -- an object.
kono
parents:
diff changeset
162 TObj_ByFunc : Tag_Type := Tag_Value; -- Initial assignment is
kono
parents:
diff changeset
163 -- function return value.
kono
parents:
diff changeset
164 Ren_Obj : Tag_Type renames TObj_ByAgg;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 begin
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 begin
kono
parents:
diff changeset
169 if (TObj_ByAgg.Disc /= 5) or (TObj_ByAgg.S /= "Hello") then
kono
parents:
diff changeset
170 Report.Failed ("Wrong initial values for TObj_ByAgg");
kono
parents:
diff changeset
171 end if;
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 TObj_ByAgg := (2, "Hi"); -- C_E, can't change the
kono
parents:
diff changeset
174 -- value of the discriminant.
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 Avoid_Optimization_and_Fail (TObj_ByAgg, "Subtest 1");
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 exception
kono
parents:
diff changeset
179 when Constraint_Error => null; -- Exception is expected.
kono
parents:
diff changeset
180 when others =>
kono
parents:
diff changeset
181 Report.Failed ("Unexpected exception - Subtest 1");
kono
parents:
diff changeset
182 end;
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 begin
kono
parents:
diff changeset
186 Assign_Tag (Ren_Obj); -- C_E, can't change the
kono
parents:
diff changeset
187 -- value of the discriminant.
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 Avoid_Optimization_and_Fail (Ren_Obj, "Subtest 2");
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 exception
kono
parents:
diff changeset
192 when Constraint_Error => null; -- Exception is expected.
kono
parents:
diff changeset
193 when others =>
kono
parents:
diff changeset
194 Report.Failed ("Unexpected exception - Subtest 2");
kono
parents:
diff changeset
195 end;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 begin
kono
parents:
diff changeset
199 if (TObj_ByObj.Disc /= 5) or (TObj_ByObj.S /= "Hello") then
kono
parents:
diff changeset
200 Report.Failed ("Wrong initial values for TObj_ByObj");
kono
parents:
diff changeset
201 end if;
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 TObj_ByObj := (3, "Bye"); -- C_E, can't change the
kono
parents:
diff changeset
204 -- value of the discriminant.
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 Avoid_Optimization_and_Fail (TObj_ByObj, "Subtest 3");
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 exception
kono
parents:
diff changeset
209 when Constraint_Error => null; -- Exception is expected.
kono
parents:
diff changeset
210 when others =>
kono
parents:
diff changeset
211 Report.Failed ("Unexpected exception - Subtest 3");
kono
parents:
diff changeset
212 end;
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 begin
kono
parents:
diff changeset
216 if (TObj_ByFunc.Disc /= 4) or (TObj_ByFunc.S /= "ACVC") then
kono
parents:
diff changeset
217 Report.Failed ("Wrong initial values for TObj_ByFunc");
kono
parents:
diff changeset
218 end if;
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 TObj_ByFunc := (5, "Aloha"); -- C_E, can't change the
kono
parents:
diff changeset
221 -- value of the discriminant.
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 Avoid_Optimization_and_Fail (TObj_ByFunc, "Subtest 4");
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 exception
kono
parents:
diff changeset
226 when Constraint_Error => null; -- Exception is expected.
kono
parents:
diff changeset
227 when others =>
kono
parents:
diff changeset
228 Report.Failed ("Unexpected exception - Subtest 4");
kono
parents:
diff changeset
229 end;
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 end TagObj_Block;
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 ArrObj_Block:
kono
parents:
diff changeset
235 declare
kono
parents:
diff changeset
236 Arr_Const : constant Array_Type
kono
parents:
diff changeset
237 := (9, 7, 6, 8);
kono
parents:
diff changeset
238 Arr_ByAgg : Array_Type -- Initial assignment is
kono
parents:
diff changeset
239 := (10, 11, 12); -- aggregate.
kono
parents:
diff changeset
240 Arr_ByFunc : Array_Type -- Initial assignment is
kono
parents:
diff changeset
241 := Array_Value; -- function return value.
kono
parents:
diff changeset
242 Arr_ByObj : Array_Type -- Initial assignment is
kono
parents:
diff changeset
243 := Arr_ByAgg; -- object.
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 Arr_Obj : array (Positive range <>) of Integer
kono
parents:
diff changeset
246 := (1, 2, 3, 4, 5);
kono
parents:
diff changeset
247 begin
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 begin
kono
parents:
diff changeset
250 if (Arr_Const'First /= 1) or (Arr_Const'Last /= 4) then
kono
parents:
diff changeset
251 Report.Failed ("Wrong bounds for Arr_Const");
kono
parents:
diff changeset
252 end if;
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 if (Arr_ByAgg'First /= 1) or (Arr_ByAgg'Last /= 3) then
kono
parents:
diff changeset
255 Report.Failed ("Wrong bounds for Arr_ByAgg");
kono
parents:
diff changeset
256 end if;
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 if (Arr_ByFunc'First /= 1) or (Arr_ByFunc'Last /= 2) then
kono
parents:
diff changeset
259 Report.Failed ("Wrong bounds for Arr_ByFunc");
kono
parents:
diff changeset
260 end if;
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 if (Arr_ByObj'First /= 1) or (Arr_ByObj'Last /= 3) then
kono
parents:
diff changeset
263 Report.Failed ("Wrong bounds for Arr_ByObj");
kono
parents:
diff changeset
264 end if;
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 Assign_Array (Arr_ByObj); -- C_E, Arr_ByObj bounds are
kono
parents:
diff changeset
267 -- 1..3.
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 Report.Failed ("Constraint_Error not raised - Subtest 5");
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 exception
kono
parents:
diff changeset
272 when Constraint_Error => null; -- Exception is expected.
kono
parents:
diff changeset
273 when others =>
kono
parents:
diff changeset
274 Report.Failed ("Unexpected exception - Subtest 5");
kono
parents:
diff changeset
275 end;
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 begin
kono
parents:
diff changeset
279 if (Arr_Obj'First /= 1) or (Arr_Obj'Last /= 5) then
kono
parents:
diff changeset
280 Report.Failed ("Wrong bounds for Arr_Obj");
kono
parents:
diff changeset
281 end if;
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 for I in 0 .. 5 loop
kono
parents:
diff changeset
284 Arr_Obj (I + 1) := I + 5; -- C_E, Arr_Obj bounds are
kono
parents:
diff changeset
285 end loop; -- 1..5.
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 Report.Failed ("Constraint_Error not raised - Subtest 6");
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 exception
kono
parents:
diff changeset
290 when Constraint_Error => null; -- Exception is expected.
kono
parents:
diff changeset
291 when others =>
kono
parents:
diff changeset
292 Report.Failed ("Unexpected exception - Subtest 6");
kono
parents:
diff changeset
293 end;
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 end ArrObj_Block;
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 GenericObj_Block:
kono
parents:
diff changeset
299 declare
kono
parents:
diff changeset
300 type Rec (Disc : Small_Num) is
kono
parents:
diff changeset
301 record
kono
parents:
diff changeset
302 S : Small_Num := Disc;
kono
parents:
diff changeset
303 end record;
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 Rec_Obj : Rec := (2, 2);
kono
parents:
diff changeset
306 package IGen is new Gen (Rec, Rec_Obj);
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 begin
kono
parents:
diff changeset
309 IGen.Gen_Obj := (3, 3); -- C_E, can't change the
kono
parents:
diff changeset
310 -- value of the discriminant.
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 Report.Failed ("Constraint_Error not raised - Subtest 7");
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 -- Next line prevents dead assignment.
kono
parents:
diff changeset
315 Report.Comment ("Disc is" & Integer'Image (IGen.Gen_Obj.Disc));
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 exception
kono
parents:
diff changeset
318 when Constraint_Error => null; -- Exception is expected.
kono
parents:
diff changeset
319 when others =>
kono
parents:
diff changeset
320 Report.Failed ("Unexpected exception - Subtest 7");
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 end GenericObj_Block;
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 Report.Result;
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 end C330002;