comp.lang.ada
 help / color / mirror / Atom feed
* How many Ada compiler bugs are here?
@ 2012-01-12 23:20 Maciej Sobczak
  2012-01-13  0:21 ` Randy Brukardt
  0 siblings, 1 reply; 41+ messages in thread
From: Maciej Sobczak @ 2012-01-12 23:20 UTC (permalink / raw)


Consider:

with Ada.Finalization;
with Ada.Text_IO;

procedure Test is

   package P is
      Some_Error : exception;
      type T (<>) is limited private;
      function Make_T return T;
   private
      type T is new Ada.Finalization.Limited_Controlled with
         record
            Initialized : Boolean := False;
         end record;

      overriding procedure Adjust (V : in out T);
      overriding procedure Finalize (V : in out T);
   end P;

   package body P is
      function Make_T return T is
      begin
         raise Some_Error;

         --  needed to please the compiler:
         return (Ada.Finalization.Limited_Controlled
                   with others => <>);
      end Make_T;

      procedure Adjust (V : in out T) is
      begin
         Ada.Text_IO.Put_Line ("adjusting");
      end Adjust;

      procedure Finalize (V : in out T) is
      begin
         Ada.Text_IO.Put_Line
           ("finalizing with Initialized =" &
              Boolean'Image (V.Initialized));
      end Finalize;
   end P;

begin
   declare
      Tmp : P.T := P.Make_T;
   begin
      null;
   end;
exception
   when others =>
      Ada.Text_IO.Put_Line ("exception handled");
end Test;

This program prints (GNAT 2011):

$ ./test
finalizing with Initialized =TRUE
exception handled
$

Above:

1. Adjust should not be allowed to be declared (it is a *limited*
type). But I have defined it to trace the remaining bugs:
2. The return statement in Make_T should not be required, because it
is unreachable anyway.
3. Logically, Tmp is never created, because Make_T raises an
exception. Somehow some object is finalized. Apparently it is Tmp,
which should not exist.
4. Somehow Tmp.initialized = True, even though its default value is
defined to be False.

Guess how I found that out. It's past midnight here...

Are there any known workarounds?

--
Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com



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

end of thread, other threads:[~2012-01-20 10:43 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-12 23:20 How many Ada compiler bugs are here? Maciej Sobczak
2012-01-13  0:21 ` Randy Brukardt
2012-01-13  1:26   ` Adam Beneschan
2012-01-13  8:23     ` Dmitry A. Kazakov
2012-01-13  8:47       ` AdaMagica
2012-01-13  9:07         ` Dmitry A. Kazakov
2012-01-13  9:35           ` AdaMagica
2012-01-13 10:00             ` Dmitry A. Kazakov
2012-01-13 10:38               ` georg bauhaus
2012-01-13 11:39                 ` Dmitry A. Kazakov
2012-01-13 12:43                   ` Georg Bauhaus
2012-01-13 13:06                     ` AdaMagica
2012-01-13 13:16                       ` AdaMagica
2012-01-13 13:22                       ` Georg Bauhaus
2012-01-13 13:29                         ` Dmitry A. Kazakov
2012-01-13 10:52               ` AdaMagica
2012-01-13 11:35                 ` Dmitry A. Kazakov
2012-01-13 12:58                   ` AdaMagica
2012-01-13 13:43                     ` Dmitry A. Kazakov
2012-01-13 15:06                       ` Robert A Duff
2012-01-13 15:46                         ` Dmitry A. Kazakov
2012-01-13 17:42                           ` georg bauhaus
2012-01-13 18:52                             ` Dmitry A. Kazakov
2012-01-14  0:26                           ` Randy Brukardt
2012-01-14  9:49                             ` Dmitry A. Kazakov
2012-01-19  1:35                               ` Randy Brukardt
2012-01-19 10:33                                 ` Dmitry A. Kazakov
2012-01-14  2:41                           ` Robert A Duff
2012-01-13 17:23               ` Adam Beneschan
2012-01-14  2:41                 ` Robert A Duff
2012-01-13 17:15       ` Adam Beneschan
2012-01-13 20:06   ` Blady
2012-01-13 23:30     ` Adam Beneschan
2012-01-14 13:29       ` Brian Drummond
2012-01-19  1:47         ` Randy Brukardt
2012-01-19  4:24           ` Adam Beneschan
2012-01-20  0:04             ` Randy Brukardt
2012-01-14 10:20   ` Maciej Sobczak
2012-01-14 14:03     ` Brian Drummond
2012-01-16 16:35     ` Adam Beneschan
2012-01-20 10:43       ` Brian Drummond

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