comp.lang.ada
 help / color / mirror / Atom feed
* 'for cursor in container.first loop' bug?
@ 2014-08-28 17:56 Stephen Leake
  2014-08-28 19:56 ` Randy Brukardt
  2014-08-28 20:46 ` Simon Wright
  0 siblings, 2 replies; 6+ messages in thread
From: Stephen Leake @ 2014-08-28 17:56 UTC (permalink / raw)


I'm trying to use the 'for cursor in container.first loop' syntax in Ada
2012 with my own container, and having lots of problems.

So first I tried a simple example using Ada.Containers.Vector, with GNAT
2014:

with Ada.Text_Io; use Ada.Text_Io;
with Ada.Containers.Vectors;
procedure Try_Containers
is
   package Integer_Vectors is new Ada.Containers.Vectors (Natural, Integer);
   use Integer_Vectors;

   A : Vector := To_Vector (1, 10);
begin
   Loop_1 :
   for Element of A loop
      Put_Line ("A (i) => " & Integer'Image (Element));
      -- can't do Element := 2;
   end loop Loop_1;

   Loop_2 :
   for Cursor in First (A) loop
      Put_Line ("A (I) => " & Integer'Image (Element (Cursor)));
      Replace_Element (A, Cursor, 2);
      Reference (A, Cursor) := 2;
   end loop Loop_2;

end Try_Containers;

This gives compilation errors:

gnatmake -k ../try_containers.adb
gcc -c -I../ -I- ../try_containers.adb
try_containers.adb:17:28: invalid prefix in call
try_containers.adb:17:28: invalid prefix in selected component "I572b"
gnatmake: "../try_containers.adb" compilation error

Same error (with a different generated name) with GnatPro 7.2.

Commenting out loop_2 gives the expected results.

Am I missing something simple, or is this a compiler bug? At the very
least, it's not a good error message.

-- 
-- Stephe

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-08-29 14:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-28 17:56 'for cursor in container.first loop' bug? Stephen Leake
2014-08-28 19:56 ` Randy Brukardt
2014-08-29 13:52   ` Stephen Leake
2014-08-28 20:46 ` Simon Wright
2014-08-29  3:16   ` Randy Brukardt
2014-08-29 14:03   ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox