Labeled exit bug in GNAT GPL 2012 confirmed
While trying out the new Ada 2012 loop syntax, I discovered what appeared to be a bug in the compiler: I could not use labeled exit statements when using the new loop syntax. Observe this simple example:
with Ada.Text_IO; procedure Loopy is use Ada.Text_IO; Foo : array (1 .. 3) of String (1 .. 3) := (2 => "Bar", others => "Foo"); begin -- Classic loop syntax for I in Foo'Range loop Put_Line (Foo (I)); end loop; -- New loop syntax for K of Foo loop Put_Line (K); end loop; end Loopy; |
Compiling this with the -gnat2012 works like a charm and output from the program is as expected:
Foo Bar Foo Foo Bar Foo
Obviously using labeled loops/exits in this example is more or less completely pointless, but since I’m a bit of a renegade (and for the sake of the argument), I’m going to do it anyway. Lets see what happens:
with Ada.Text_IO; procedure Loopy is use Ada.Text_IO; Foo : array (1 .. 3) of String (1 .. 3) := (2 => "Bar", others => "Foo"); begin -- Classic loop syntax Loop_Classic : for I in Foo'Range loop exit Loop_Classic When Foo (I) = "Bar"; Put_Line (Foo (I)); end loop Loop_Classic; -- New loop syntax Loop_New : for K of Foo loop exit Loop_New when K = "Bar"; Put_Line (K); end loop Loop_New; end Loopy; |
Awesome labels I’ve come up with eh’?
Compiling the above example yields this little puppy:
gcc -c -gnat2012 loopy.adb loopy.adb:17:07: invalid loop name in exit statement gnatmake: "loopy.adb" compilation error
Gaagle! The horror! The pain! The bug has been reported to AdaCore by Marc A. Criley, and according to this notice they’ve sorta/kinda acknowledged it.
So all we have to do now is wait for a fix. When I cried out on comp.lang.ada that I wanted my labeled exit statements back, he replied with this:
GNAT GPL 2013
Hehe.. Dry fellow that Marc. But he’s probably right. I’m just going to have to patiently wait an entire year before I can actually use the new loop syntax and labeled exit statements at the same time. I can handle that. I think.