summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/c4/c460004.a
blob: b00428121b80b13a6e2c5d1174e29b9fbc00c9b0 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
-- C460004.A
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
--      Check that if the operand type of a type conversion is class-wide,
--      Constraint_Error is raised if the tag of the operand does not
--      identify a specific type that is covered by or descended from the
--      target type.
--
-- TEST DESCRIPTION:
--      View conversions of class-wide operands to specific types are
--      placed on the right and left sides of assignment statements, and
--      conversions of class-wide operands to class-wide types are used
--      as actual parameters to dispatching operations. In all cases, a
--      check is made that Constraint_Error is raised if the tag of the
--      operand does not identify a specific type covered by or descended
--      from the target type, and not raised otherwise.
--      
--      A specific type is descended from itself and from those types it is
--      directly or indirectly derived from. A specific type is covered by
--      itself and each class-wide type to whose class it belongs.
--      
--      A class-wide type T'Class is descended from T and those types which
--      T is descended from. A class-wide type is covered by each class-wide
--      type to whose class it belongs.
--      
--
-- CHANGE HISTORY:
--      19 Jul 95   SAIC    Initial prerelease version.
--      18 Apr 96   SAIC    ACVC 2.1: Added a check for correct tag.
--
--!
package C460004_0 is

   type Tag_Type is tagged record
      C1 : Natural;
   end record;

   procedure Proc (X : in out Tag_Type);


   type DTag_Type is new Tag_Type with record
      C2 : String (1 .. 5);
   end record;

   procedure Proc (X : in out DTag_Type);


   type DDTag_Type is new DTag_Type with record
      C3 : String (1 .. 5);
   end record;

   procedure Proc (X : in out DDTag_Type);

   procedure NewProc (X : in DDTag_Type);

   function CWFunc (X : Tag_Type'Class) return Tag_Type'Class;

end C460004_0;


     --==================================================================--

with Report;
package body C460004_0 is

   procedure Proc (X : in out Tag_Type) is
   begin
      X.C1 := 25;
   end Proc;

   -----------------------------------------
   procedure Proc (X : in out DTag_Type) is
   begin
      Proc ( Tag_Type(X) );
      X.C2 := "Earth";
   end Proc;

   -----------------------------------------
   procedure Proc (X : in out DDTag_Type) is
   begin
      Proc ( DTag_Type(X) );
      X.C3 := "Orbit";
   end Proc;

   -----------------------------------------
   procedure NewProc (X : in DDTag_Type) is
      Y : DDTag_Type := X;
   begin
      Proc (Y);
   exception
      when others => 
         Report.Failed ("Unexpected exception in NewProc");
   end NewProc;

   -----------------------------------------
   function CWFunc (X : Tag_Type'Class) return Tag_Type'Class is
      Y : Tag_Type'Class := X;
   begin
      Proc (Y);
      return Y;
   end CWFunc;

end C460004_0;


     --==================================================================--


with C460004_0;
use  C460004_0;

with Report;
procedure C460004 is

   Tag_Type_Init    :  constant Tag_Type   := (C1 => 0);
   DTag_Type_Init   :  constant DTag_Type  := (Tag_Type_Init with "Hello");
   DDTag_Type_Init  :  constant DDTag_Type := (DTag_Type_Init with "World");

   Tag_Type_Value   :  constant Tag_Type   := (C1 => 25);
   DTag_Type_Value  :  constant DTag_Type  := (Tag_Type_Value  with "Earth");
   DDTag_Type_Value :  constant DDTag_Type := (DTag_Type_Value with "Orbit");

begin

   Report.Test ("C460004", "Check that for a view conversion of a "      &
                "class-wide operand, Constraint_Error is raised if the " &
                "tag of the operand does not identify a specific type "  &
                "covered by or descended from the target type");

--
-- View conversion to specific type:
--

   declare
      procedure CW_Proc (P : Tag_Type'Class) is
         Target : Tag_Type := Tag_Type_Init;     
      begin
         Target := Tag_Type(P);                      
         if (Target /= Tag_Type_Value) then
            Report.Failed ("Target has wrong value: #01");
         end if;
      exception
         when Constraint_Error => 
            Report.Failed ("Constraint_Error raised: #01");
         when others           => 
            Report.Failed ("Unexpected exception: #01");
      end CW_Proc;

   begin
      CW_Proc (DDTag_Type_Value);
   end;

   ----------------------------------------------------------------------

   declare
      Target : DTag_Type := DTag_Type_Init;           
   begin
      Target := DTag_Type(CWFunc(DDTag_Type_Value));  
      if (Target /= DTag_Type_Value) then
         Report.Failed ("Target has wrong value: #02");
      end if;
   exception
      when Constraint_Error => Report.Failed ("Constraint_Error raised: #02");
      when others           => Report.Failed ("Unexpected exception: #02");
   end;

   ----------------------------------------------------------------------

   declare
      Target : DDTag_Type;
   begin
      Target := DDTag_Type(CWFunc(Tag_Type_Value));
                -- CWFunc returns a Tag_Type; its tag is preserved through 
                -- the view conversion.  Constraint_Error should be raised.

      Report.Failed ("Constraint_Error not raised: #03"); 

   exception
      when Constraint_Error => null;                 -- expected exception
      when others           => Report.Failed ("Unexpected exception: #03");
   end;

   ----------------------------------------------------------------------

   declare
      procedure CW_Proc (P : Tag_Type'Class) is
      begin
         NewProc (DDTag_Type(P));
         Report.Failed ("Constraint_Error not raised: #04"); 
                                                         
      exception
         when Constraint_Error => null;              -- expected exception
         when others           => Report.Failed ("Unexpected exception: #04");
      end CW_Proc;
 
   begin
      CW_Proc (DTag_Type_Value);
   end;

   ----------------------------------------------------------------------

   declare
      procedure CW_Proc (P : Tag_Type'Class) is
         Target : DDTag_Type := DDTag_Type_Init; 
      begin
         Target := DDTag_Type(P);
         if (Target /= DDTag_Type_Value) then
            Report.Failed ("Target has wrong value: #05");
         end if;

      exception
         when Constraint_Error => 
            Report.Failed ("Constraint_Error raised: #05");
         when others           
            => Report.Failed ("Unexpected exception: #05");
      end CW_Proc;
 
   begin
      CW_Proc (DDTag_Type_Value);
   end;


--
-- View conversion to class-wide type:
--

   declare
      procedure CW_Proc (P : Tag_Type'Class) is
         Operand : Tag_Type'Class := P;
      begin
         Proc( DTag_Type'Class(Operand) );
         Report.Failed ("Constraint_Error not raised: #06");

      exception
         when Constraint_Error => null;              -- expected exception
         when others           => Report.Failed ("Unexpected exception: #06");
      end CW_Proc;
 
   begin
      CW_Proc (Tag_Type_Init);
   end;

   ----------------------------------------------------------------------

   declare
      procedure CW_Proc (P : Tag_Type'Class) is
         Operand : Tag_Type'Class := P;
      begin
         Proc( DDTag_Type'Class(Operand) );
         Report.Failed ("Constraint_Error not raised: #07");

      exception
         when Constraint_Error => null;              -- expected exception
         when others           => Report.Failed ("Unexpected exception: #07");
      end CW_Proc;
 
   begin
      CW_Proc (Tag_Type_Init);
   end;

   ----------------------------------------------------------------------

   declare
      procedure CW_Proc (P : Tag_Type'Class) is
         Operand : Tag_Type'Class := P;
      begin
         Proc( DTag_Type'Class(Operand) );  
         if Operand not in DTag_Type then
            Report.Failed ("Operand has wrong tag: #08");
         elsif (Operand /= Tag_Type'Class (DTag_Type_Value)) then
            Report.Failed ("Operand has wrong value: #08");
         end if;

      exception
         when Constraint_Error => 
            Report.Failed ("Constraint_Error raised: #08");
         when others           => 
            Report.Failed ("Unexpected exception: #08");
      end CW_Proc;
 
   begin
      CW_Proc (DTag_Type_Init);
   end;

   ----------------------------------------------------------------------

   declare
      procedure CW_Proc (P : Tag_Type'Class) is
         Operand : Tag_Type'Class := P;
      begin
         Proc( Tag_Type'Class(Operand) );
         if Operand not in DDTag_Type then
            Report.Failed ("Operand has wrong tag: #09");
         elsif (Operand /= Tag_Type'Class (DDTag_Type_Value)) then
            Report.Failed ("Operand has wrong value: #09");
         end if;

      exception
         when Constraint_Error => 
            Report.Failed ("Constraint_Error raised: #09");
         when others           => 
            Report.Failed ("Unexpected exception: #09");
      end CW_Proc;
 
   begin
      CW_Proc (DDTag_Type_Init);
   end;


   Report.Result;

end C460004;