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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5d4ade2fd8fd67c6 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news.glorb.com!solaris.cc.vt.edu!news.vt.edu!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Legit Warnings or not Date: Wed, 20 Jul 2011 19:16:55 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <531193e0-3305-4292-9ed8-0176226c1d00@x12g2000yql.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1311203815 5794 192.74.137.71 (20 Jul 2011 23:16:55 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 20 Jul 2011 23:16:55 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:ehJC5M4NEZxfH4bFYJH1KZue+2g= Xref: g2news2.google.com comp.lang.ada:21223 Date: 2011-07-20T19:16:55-04:00 List-Id: Anh Vo writes: > package Warnings_Legit is > > type Warned_Person (Size : Positive := 10) is -- Warnings issued > here > record > Name : String (1 .. Size); > end record; > > type Acceptable_Person (Size : Positive) is > record > Name : String (1 .. Size); > end record; > > end Warnings_Legit; > > The code segment above triggers a warnings message 'creation of > "Warned_Person" object may raise Storage_Error' at line 3 as marked. > However, no warnings is issued at line 8. The difference between them > is default discriminant. I am using GNAT-GPL-2011. There's a confusing rule in Ada: If it has defaults, there can be unconstrained objects of that type (and also constrained ones). If it doesn't have defaults, then all objects must be constrained. So if you say "X : Warned_Person;", GNAT will allocate space for billions of characters (not just 10) because you might assign a bigger one (like "X := (Size => 1_000_000, Name => Something)"). > Is this warnings legitimate? If yes, why line 8 is OK. Otherwise, > should it be a bug? It's not a bug. An object of type Warned_Person might need huge amounts of memory, so Storage_Error might well be raised. It's illegal to say "X : Acceptable_Person;", so that one doesn't get a warning. If you want unconstrained objects, use a reasonably-small size, like: subtype Name_Length is Natural range 0..1000; type Not_Warned_Person (Size : Name_Length := 0) is record Name : String (1 .. Size); end record; Unconstrained objects of type Not_Warned_Person will then require space for 1000 characters. On the other hand, if you don't want unconstrained objects, don't give a default (as in your Acceptable_Person). - Bob