summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/c3/c380003.a
blob: 451d177036cc753bc5754175e55547f2e5a1e035 (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
-- C380003.A
--
--                             Grant of Unlimited Rights
--
--     The Ada Conformity Assessment Authority (ACAA) holds unlimited
--     rights in the software and documentation contained herein. Unlimited
--     rights are the same as those granted by the U.S. Government for older
--     parts of the Ada Conformity Assessment Test Suite, and are defined
--     in DFAR 252.227-7013(a)(19). By making this public release, the ACAA
--     intends to confer upon all recipients unlimited rights equal to those
--     held by the ACAA. 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 ACAA 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 per-object expressions are evaluated as specified for
--    protected components.  (Defect Report 8652/0002, as reflected in
--    Technical Corrigendum 1, RM95 3.6(22/1) and 3.8(18/1)).
--
-- CHANGE HISTORY:
--     9 FEB 2001   PHL   Initial version.
--    29 JUN 2002   RLB   Readied for release.
--
--!
with Report;
use Report;
procedure C380003 is

    subtype Sm is Integer range 1 .. 10;

    type Rec (D1, D2 : Sm) is
        record
            null;
        end record;

begin
    Test ("C380003",
          "Check compatibility of discriminant expressions" &
             " when the constraint depends on discriminants, " &
             "and the discriminants have defaults - protected components");

    declare
        protected type Cons (D3 : Integer := Ident_Int (11)) is
            function C1_D1 return Integer;
            function C1_D2 return Integer;
        private
            C1 : Rec (D3, 1);
        end Cons;
        protected body Cons is
            function C1_D1 return Integer is
            begin
                return C1.D1;
            end C1_D1;
            function C1_D2 return Integer is
            begin
                return C1.D2;
            end C1_D2;
        end Cons;

        function Is_Ok
                    (C : Cons; D3 : Integer; C1_D1 : Integer; C1_D2 : Integer)
                    return Boolean is
        begin
            return C.D3 = D3 and C.C1_D1 = C1_D1 and C.C1_D2 = C1_D2;
        end Is_Ok;

    begin
        begin
            declare
                X : Cons;
            begin
                Failed ("Discriminant check not performed - 1");
                if not Is_Ok (X, 1, 1, 1) then
                    Comment ("Shouldn't get here");
                end if;
            end;
        exception
            when Constraint_Error =>
                null;
            when others =>
                Failed ("Unexpected exception - 1");
        end;

        begin
            declare
                type Acc_Cons is access Cons;
                X : Acc_Cons;
            begin
                X := new Cons;
                Failed ("Discriminant check not performed - 2");
                begin
                    if not Is_Ok (X.all, 1, 1, 1) then
                        Comment ("Irrelevant");
                    end if;
                end;
            exception
                when Constraint_Error =>
                    null;
                when others =>
                    Failed ("Unexpected exception raised - 2");
            end;
        exception
            when others =>
                Failed ("Constraint checked too soon - 2");
        end;

        begin
            declare
                subtype Scons is Cons;
            begin
                declare
                    X : Scons;
                begin
                    Failed ("Discriminant check not performed - 3");
                    if not Is_Ok (X, 1, 1, 1) then
                        Comment ("Irrelevant");
                    end if;
                end;
            exception
                when Constraint_Error =>
                    null;
                when others =>
                    Failed ("Unexpected exception raised - 3");
            end;
        exception
            when others =>
                Failed ("Constraint checked too soon - 3");
        end;

        begin
            declare
                type Arr is array (1 .. 5) of Cons;
            begin
                declare
                    X : Arr;
                begin
                    Failed ("Discriminant check not performed - 4");
                    for I in Arr'Range loop
                        if not Is_Ok (X (I), 1, 1, 1) then
                            Comment ("Irrelevant");
                        end if;
                    end loop;
                end;
            exception
                when Constraint_Error =>
                    null;
                when others =>
                    Failed ("Unexpected exception raised - 4");
            end;
        exception
            when others =>
                Failed ("Constraint checked too soon - 4");
        end;

        begin
            declare
                type Nrec is
                    record
                        C1 : Cons;
                    end record;
            begin
                declare
                    X : Nrec;
                begin
                    Failed ("Discriminant check not performed - 5");
                    if not Is_Ok (X.C1, 1, 1, 1) then
                        Comment ("Irrelevant");
                    end if;
                end;
            exception
                when Constraint_Error =>
                    null;
                when others =>
                    Failed ("Unexpected exception raised - 5");
            end;
        exception
            when others =>
                Failed ("Constraint checked too soon - 5");
        end;

        begin
            declare
                type Drec is new Cons;
            begin
                declare
                    X : Drec;
                begin
                    Failed ("Discriminant check not performed - 6");
                    if not Is_Ok (Cons (X), 1, 1, 1) then
                        Comment ("Irrelevant");
                    end if;
                end;
            exception
                when Constraint_Error =>
                    null;
                when others =>
                    Failed ("Unexpected exception raised - 6");
            end;
        exception
            when others =>
                Failed ("Constraint checked too soon - 6");
        end;

    end;

    Result;

exception
    when others =>
        Failed ("Constraint check done too early");
        Result;
end C380003;