Created
December 8, 2012 10:40
-
-
Save ytomino/4239744 to your computer and use it in GitHub Desktop.
built-in-place bug of gcc-4.7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function alloc return access lifetime.T is | |
begin | |
return new lifetime.T'(lifetime.Create); | |
-- lifetime.Finalize may be called here | |
end alloc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with lifetime; | |
function alloc return access lifetime.T; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Ada.Text_IO; | |
with Ada.Unchecked_Deallocation; | |
with lifetime; | |
with alloc; | |
procedure bip_and_finalize is | |
begin | |
Ada.Text_IO.Put_Line ("before"); | |
declare | |
type A is access all lifetime.T; | |
procedure Free is new Ada.Unchecked_Deallocation (lifetime.T, A); | |
P : A := A(alloc); | |
begin | |
-- P.all may be already finalized!!! | |
Ada.Text_IO.Put_Line ("lifetime"); | |
Free (P); -- lifetime.Finalize may be called, once again | |
end; | |
Ada.Text_IO.Put_Line ("after"); | |
end bip_and_finalize; | |
-- % gnatmake -gnat2012 bip_and_finalize.adb && ./bip_and_finalize | |
-- before | |
-- Initialize (0000000100100090) | |
-- Finalize (0000000100100090) <- !!!! | |
-- lifetime | |
-- Finalize (0000000100100090) | |
-- after |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Ada.Text_IO; | |
with System.Address_Image; | |
package body lifetime is | |
procedure Finalize (Object : in out T) is | |
begin | |
Ada.Text_IO.Put_Line ("Finalize (" & System.Address_Image (Object'Address) & ")"); | |
end Finalize; | |
function Create return T is | |
begin | |
return Result : T := (Ada.Finalization.Limited_Controlled with null record) do | |
Ada.Text_IO.Put_Line ("Initialize (" & System.Address_Image (Result'Address) & ")"); | |
end return; | |
end Create; | |
end lifetime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Ada.Finalization; | |
package lifetime is | |
type T is limited private; | |
function Create return T; | |
private | |
type T is limited new Ada.Finalization.Limited_Controlled with null record; | |
overriding procedure Finalize (Object : in out T); | |
end lifetime; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment