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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Peculiarities of "of" syntax Date: Sat, 11 Jan 2020 21:25:49 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 11 Jan 2020 20:25:50 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="8985623b378f925d1f9843cc24c12628"; logging-data="14767"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19BLX5wvQTOU+Hc7h7zK/eeFg+YIOI+VGI=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 Cancel-Lock: sha1:wFGIFME6PQ4dixfT2/ElYmBCGoY= In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57829 Date: 2020-01-11T21:25:49+01:00 List-Id: On 1/11/20 7:05 PM, Alejandro R. Mosteo wrote: > > procedure Pro is >    type Int_Array is array (Positive range <>) of Integer; >    Arr : Int_Array := (others => 0); > begin > >    -- 1) >    for Z of Arr loop -- of course valid >       null; >    end loop; > >    -- 2) >    for Z of Int_Array'(Arr & Arr) loop -- also works >       null; >    end loop; > >    -- INVALID > >    -- 3) >    for Z of Arr & Arr loop >      --  Error is "missing loop" >      null; >    end loop; > >    -- 4) >    for Z of (Arr & Arr) loop >       --  Error is "name expected" >       null; >    end loop; > > end Pro; There is clearly a compiler error (I get the same errors with GNAT 9.2.1). If I comment out the rejected cases, I get $ gnatmake pro.adb x86_64-linux-gnu-gcc-9 -c pro.adb pro.adb:3:24: "others" choice not allowed here gnatmake: "pro.adb" compilation error as I expected. The declaration of Arr is invalid. The compiler should have reported that error even if some of the loops are invalid. If I change line 3 to Arr : Int_Array (1 .. 10) := (others => 0); then it still complains about the last 2 loops. I'm not familiar enough with the "of" syntax to know if that's expected or another compiler error. -- Jeff Carter "Friends don't let friends program in C++" Zalman Stern 114