From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3b637950a34ec2d6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-10 02:31:55 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!lnewspeer00.lnd.ops.eu.uu.net!lnewspost00.lnd.ops.eu.uu.net!emea.uu.net!read.news.fr.uu.net!not-for-mail Sender: briot@lyon.act-europe.fr Newsgroups: comp.lang.ada Subject: Re: Discriminated record question References: <2d87db3f.0205070417.7a50667b@posting.google.com> From: Emmanuel Briot Reply-To: briot@act-europe.fr Date: 10 May 2002 11:27:32 +0200 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: lyon.act-europe.fr X-Trace: 1021023113 read.news.fr.uu.net 198 212.157.227.160 X-Complaints-To: abuse@fr.uu.net Xref: archiver1.google.com comp.lang.ada:23827 Date: 2002-05-10T11:27:32+02:00 List-Id: Mark.Doherty@uk.thalesgroup.com (Mark Doherty) writes: > Why does the following raise a constraint error on the declaration of > 'B'. > > procedure Test is > type A_Type (Text_Size : Natural := 0) is > record > Text : String (1 .. 0); > end record; > A : A_Type; > > type B_Type (Text_Size : Natural := 0) is > record > Text : String (1 .. Text_Size); > end record; > > B : B_Type; > > begin > null; > end Test; Because when you specify a default value for the discriminant, the compiler must allocate the maximum possible size (in that case Natural'Last), so you are trying to declare a huge variable, which raises CE. I thought it would have raised Storage_Error, but it might be compiler-dependent Compiling the code above with GNAT gives a proper warning gcc -c t8.adb t8.adb:10:33: warning: creation of object of this type may raise Storage_Error t8.adb:13:05: warning: Storage_Error will be raised at run-time gnatbind -x t8.ali gnatlink t8.ali