1-- C420001.A
2--
3--                             Grant of Unlimited Rights
4--
5--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687 and
6--     F08630-91-C-0015, the U.S. Government obtained unlimited rights in the
7--     software and documentation contained herein.  Unlimited rights are
8--     defined in DFAR 252.227-7013(a)(19).  By making this public release,
9--     the Government intends to confer upon all recipients unlimited rights
10--     equal to those held by the Government.  These rights include rights to
11--     use, duplicate, release or disclose the released technical data and
12--     computer software in whole or in part, in any manner and for any purpose
13--     whatsoever, and to have or permit others to do so.
14--
15--                                    DISCLAIMER
16--
17--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
18--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
19--     WARRANTY AS TO ANY MATTER WHATSOVER, INCLUDING THE CONDITIONS OF THE
20--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
21--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
22--     PARTICULAR PURPOSE OF SAID MATERIAL.
23--*
24--
25-- OBJECTIVE
26--     Check that if the index subtype of a string type is a modular subtype
27--     whose lower bound is zero, then the evaluation of a null string_literal
28--     raises Constraint_Error. This was confirmed by AI95-00138.
29--
30-- TEST DESCRIPTION
31--     In this test, we have a generic formal modular type, and we have
32--     several null string literals of that type.  Because the type is
33--     generic formal, the string literals are not static, and therefore
34--     the Constraint_Error should be detected at run time.
35--
36-- CHANGE HISTORY:
37--      29 JUN 1999   RAD   Initial Version
38--      23 SEP 1999   RLB   Improved comments and messages, renamed, issued.
39--
40--!
41with Report; use Report; pragma Elaborate_All(Report);
42with System;
43procedure C420001 is
44    generic
45        type Modular is mod <>;
46    package Mod_Test is
47        type Str is array(Modular range <>) of Character;
48        procedure Test_String_Literal;
49    end Mod_Test;
50
51    package body Mod_Test is
52        procedure Test_String_Literal is
53        begin
54            begin
55                declare
56                    Null_String: Str := ""; -- Should raise C_E.
57                begin
58                    Comment(String(Null_String)); -- Avoid 11.6 issues.
59                end;
60                Failed("Null string didn't raise Constraint_Error");
61            exception
62                when Exc: Constraint_Error =>
63                    null; -- Comment("Constraint_Error -- OK");
64                when Exc2: others =>
65                    Failed("Null string raised wrong exception");
66            end;
67            begin
68                Failed(String(Str'(""))); -- Should raise C_E, not do Failed.
69                Failed("Null string didn't raise Constraint_Error");
70            exception
71                when Exc: Constraint_Error =>
72                    null; -- Comment("Constraint_Error -- OK");
73                when Exc2: others =>
74                    Failed("Null string raised wrong exception");
75            end;
76        end Test_String_Literal;
77    begin
78        Test_String_Literal;
79    end Mod_Test;
80begin
81    Test("C420001", "Check that if the index subtype of a string type is a " &
82                    "modular subtype whose lower bound is zero, then the " &
83                    "evaluation of a null string_literal raises " &
84                    "Constraint_Error. ");
85    declare
86        type M1 is mod 1;
87        package Test_M1 is new Mod_Test(M1);
88        type M2 is mod 2;
89        package Test_M2 is new Mod_Test(M2);
90        type M3 is mod 3;
91        package Test_M3 is new Mod_Test(M3);
92        type M4 is mod 4;
93        package Test_M4 is new Mod_Test(M4);
94        type M5 is mod 5;
95        package Test_M5 is new Mod_Test(M5);
96        type M6 is mod 6;
97        package Test_M6 is new Mod_Test(M6);
98        type M7 is mod 7;
99        package Test_M7 is new Mod_Test(M7);
100        type M8 is mod 8;
101        package Test_M8 is new Mod_Test(M8);
102        type M_Max_Binary_Modulus is mod System.Max_Binary_Modulus;
103        package Test_M_Max_Binary_Modulus is new Mod_Test(M_Max_Binary_Modulus);
104        type M_Max_Nonbinary_Modulus is mod System.Max_Nonbinary_Modulus;
105        package Test_M_Max_Nonbinary_Modulus is new Mod_Test(M_Max_Nonbinary_Modulus);
106    begin
107        null;
108    end;
109    Result;
110end C420001;
111