aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/ada/acats/tests/c6/c650001.a
blob: 595e81dad4715b1c92fc208820e99ff8738ce4fe (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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
-- C650001.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, for a function result type that is a return-by-reference
--      type, Program_Error is raised if the return expression is a name that
--      denotes an object view whose accessibility level is deeper than that
--      of the master that elaborated the function body.
--      
--      Check for cases where the result type is:
--         (a) A tagged limited type.
--         (b) A task type.
--         (c) A protected type.
--         (d) A composite type with a subcomponent of a
--             return-by-reference type (task type).
--      
-- TEST DESCRIPTION:
--      The accessibility level of the master that elaborates the body of a
--      return-by-reference function will always be less deep than that of
--      the function (which is itself a master). 
--
--      Thus, the return object may not be any of the following, since each
--      has an accessibility level at least as deep as that of the function:
--
--         (1) An object declared local to the function. 
--         (2) The result of a local function.           
--         (3) A parameter of the function.              
--
--      Verify that Program_Error is raised within the return-by-reference
--      function if the return object is any of (1)-(3) above, for various
--      subsets of the return types (a)-(d) above. Include cases where (1)-(3)
--      are operands of parenthesized expressions.
--
--      Verify that no exception is raised if the return object is any of the
--      following:
--
--         (4) An object declared at a less deep level than that of the
--             master that elaborated the function body.
--         (5) The result of a function declared at the same level as the
--             original function (assuming the new function is also legal).
--         (6) A parameter of the master that elaborated the function body.
--
--      For (5), pass the new function as an actual via an access-to-
--      subprogram parameter of the original function. Check for cases where
--      the new function does and does not raise an exception.
--
--      Since the functions to be tested cannot be part of an assignment
--      statement (since they return values of a limited type), pass each
--      function result as an actual parameter to a dummy procedure, e.g.,
--
--         Dummy_Proc ( Function_Call );
--
--
-- CHANGE HISTORY:
--      03 May 95   SAIC    Initial prerelease version.
--      08 Feb 99   RLB     Removed subcase with two errors.
--
--!

package C650001_0 is

   type Tagged_Limited is tagged limited record
      C: String (1 .. 10);
   end record;

   task type Task_Type;

   protected type Protected_Type is
      procedure Op;
   end Protected_Type;

   type Task_Array is array (1 .. 10) of Task_Type;

   type Variant_Record (Toggle: Boolean) is record
      case Toggle is
         when True  =>
            T: Task_Type;  -- Return-by-reference component.
         when False =>
            I: Integer;    -- Non-return-by-reference component.
      end case;
   end record;

   -- Limited type even though variant contains no limited components:
   type Non_Task_Variant is new Variant_Record (Toggle => False);

end C650001_0;


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


package body C650001_0 is

   task body Task_Type is
   begin
      null;
   end Task_Type;

   protected body Protected_Type is
      procedure Op is
      begin
         null;
      end Op;
   end Protected_Type;

end C650001_0;


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


with C650001_0;
package C650001_1 is

   type TC_Result_Kind is (OK, P_E, O_E);

   procedure TC_Display_Results (Actual  : in TC_Result_Kind;
                                 Expected: in TC_Result_Kind;
                                 Message : in String);

   -- Dummy procedures:

   procedure Check_Tagged    (P: C650001_0.Tagged_Limited);
   procedure Check_Task      (P: C650001_0.Task_Type);
   procedure Check_Protected (P: C650001_0.Protected_Type);
   procedure Check_Composite (P: C650001_0.Non_Task_Variant);

end C650001_1;


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


with Report;
package body C650001_1 is

   procedure TC_Display_Results (Actual  : in TC_Result_Kind;
                                 Expected: in TC_Result_Kind;
                                 Message : in String) is
   begin
      if Actual /= Expected then
         case Actual is
            when OK  =>
               Report.Failed ("No exception raised: "         & Message);
            when P_E =>
               Report.Failed ("Program_Error raised: "        & Message);
            when O_E =>
               Report.Failed ("Unexpected exception raised: " & Message);
         end case;
      end if;
   end TC_Display_Results;


   procedure Check_Tagged (P: C650001_0.Tagged_Limited) is
   begin
      null;
   end;

   procedure Check_Task (P: C650001_0.Task_Type) is
   begin
      null;
   end;

   procedure Check_Protected (P: C650001_0.Protected_Type) is
   begin
      null;
   end;

   procedure Check_Composite (P: C650001_0.Non_Task_Variant) is
   begin
      null;
   end;

end C650001_1;



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


with C650001_0;
with C650001_1;

with Report;
procedure C650001 is
begin

   Report.Test ("C650001", "Check that, for a function result type that " &
                "is a return-by-reference type, Program_Error is raised " &
                "if the return expression is a name that denotes an "     &
                "object view whose accessibility level is deeper than "   &
                "that of the master that elaborated the function body");



   SUBTEST1:
   declare

      Result: C650001_1.TC_Result_Kind;
      PO    : C650001_0.Protected_Type;

      function Return_Prot (P: C650001_0.Protected_Type)
        return C650001_0.Protected_Type is
      begin
         Result := C650001_1.OK;
         return P;                                     -- Formal parameter (3).
      exception
         when Program_Error =>
            Result := C650001_1.P_E;                        -- Expected result.
            return PO;
         when others        =>
            Result := C650001_1.O_E;
            return PO;
      end Return_Prot;

   begin  -- SUBTEST1.
      C650001_1.Check_Protected ( Return_Prot(PO) );
      C650001_1.TC_Display_Results (Result, C650001_1.P_E, "SUBTEST #1");
   exception
      when others =>
         Report.Failed ("SUBTEST #1: Unexpected exception in outer block");
   end SUBTEST1;



   SUBTEST2:
   declare

      Result: C650001_1.TC_Result_Kind;
      Comp  : C650001_0.Non_Task_Variant;

      function Return_Composite return C650001_0.Non_Task_Variant is
         Local: C650001_0.Non_Task_Variant;
      begin
         Result := C650001_1.OK;
         return (Local);                     -- Parenthesized local object (1).
      exception
         when Program_Error =>
            Result := C650001_1.P_E;                        -- Expected result.
            return Comp;
         when others        =>
            Result := C650001_1.O_E;
            return Comp;
      end Return_Composite;

   begin -- SUBTEST2.
      C650001_1.Check_Composite ( Return_Composite );
      C650001_1.TC_Display_Results (Result, C650001_1.P_E, "SUBTEST #2");
   exception
      when others =>
         Report.Failed ("SUBTEST #2: Unexpected exception in outer block");
   end SUBTEST2;



   SUBTEST3:
   declare

      Result: C650001_1.TC_Result_Kind;
      Tsk   : C650001_0.Task_Type;
      TskArr: C650001_0.Task_Array;

      function Return_Task (P: C650001_0.Task_Array)
        return C650001_0.Task_Type is

         function Inner return C650001_0.Task_Type is
         begin
            return P(P'First);           -- OK: should not raise exception (6).
         exception
            when Program_Error =>
               Report.Failed ("SUBTEST #3: Program_Error incorrectly " &
                              "raised within function Inner");
               return Tsk;
            when others        =>
               Report.Failed ("SUBTEST #3: Unexpected exception " &
                              "raised within function Inner");
               return Tsk;
         end Inner;

      begin -- Return_Task.
         Result := C650001_1.OK;
         return Inner;                           -- Call to local function (2).
      exception
         when Program_Error =>
            Result := C650001_1.P_E;                        -- Expected result.
            return Tsk;
         when others        =>
            Result := C650001_1.O_E;
            return Tsk;
      end Return_Task;

   begin -- SUBTEST3.
      C650001_1.Check_Task ( Return_Task(TskArr) );
      C650001_1.TC_Display_Results (Result, C650001_1.P_E, "SUBTEST #3");
   exception
      when others =>
         Report.Failed ("SUBTEST #3: Unexpected exception in outer block");
   end SUBTEST3;



   SUBTEST4:
   declare

      Result: C650001_1.TC_Result_Kind;
      TagLim: C650001_0.Tagged_Limited;

      function Return_TagLim (P: C650001_0.Tagged_Limited'Class)
        return C650001_0.Tagged_Limited is
      begin
         Result := C650001_1.OK;
         return C650001_0.Tagged_Limited(P); -- Conversion of formal param (3).
      exception
         when Program_Error =>
            Result := C650001_1.P_E;                        -- Expected result.
            return TagLim;
         when others        =>
            Result := C650001_1.O_E;
            return TagLim;
      end Return_TagLim;

   begin -- SUBTEST4.
      C650001_1.Check_Tagged ( Return_TagLim(TagLim) );
      C650001_1.TC_Display_Results (Result, C650001_1.P_E,
                                    "SUBTEST #4 (root type)");
   exception
      when others =>
         Report.Failed ("SUBTEST #4: Unexpected exception in outer block");
   end SUBTEST4;



   SUBTEST5:
   declare
      Tsk : C650001_0.Task_Type;
   begin  -- SUBTEST5.

      declare
         Result: C650001_1.TC_Result_Kind;

         type AccToFunc is access function return C650001_0.Task_Type;

         function Return_Global return C650001_0.Task_Type is
         begin
            return Tsk;                  -- OK: should not raise exception (4).
         end Return_Global;

         function Return_Local return C650001_0.Task_Type is
            Local : C650001_0.Task_Type;
         begin
            return Local;                           -- Propagate Program_Error.
         end Return_Local;


         function Return_Func (P: AccToFunc) return C650001_0.Task_Type is
         begin
            Result := C650001_1.OK;
            return P.all;                                 -- Function call (5).
         exception
            when Program_Error =>
               Result := C650001_1.P_E;
               return Tsk;
            when others        =>
               Result := C650001_1.O_E;
               return Tsk;
         end Return_Func;

         RG : AccToFunc := Return_Global'Access;
         RL : AccToFunc := Return_Local'Access;

      begin
         C650001_1.Check_Task ( Return_Func(RG) );
         C650001_1.TC_Display_Results (Result, C650001_1.OK,
                                       "SUBTEST #5 (global task)");

         C650001_1.Check_Task ( Return_Func(RL) );
         C650001_1.TC_Display_Results (Result, C650001_1.P_E,
                                       "SUBTEST #5 (local task)");
      exception
         when others =>
            Report.Failed ("SUBTEST #5: Unexpected exception in outer block");
      end;

   end SUBTEST5;



   Report.Result;

end C650001;