From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Peculiarities of "of" syntax
Date: Sat, 11 Jan 2020 21:25:49 +0100
Date: 2020-01-11T21:25:49+01:00 [thread overview]
Message-ID: <qvdb0d$edf$1@dont-email.me> (raw)
In-Reply-To: <qvd2p1$psk$1@dont-email.me>
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
next prev parent reply other threads:[~2020-01-11 20:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-11 18:05 Peculiarities of "of" syntax Alejandro R. Mosteo
2020-01-11 20:25 ` Jeffrey R. Carter [this message]
2020-01-11 21:45 ` Robert A Duff
2020-01-12 1:38 ` Alejandro R. Mosteo
2020-01-12 2:01 ` Robert A Duff
2020-01-12 11:27 ` Simon Wright
2020-01-13 23:32 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox