Return_By_Reference or Return_By_Copy (GNAT bug?)
From: Duncan Sands (baldrick_at_free.fr)
Date: 12/31/04
- Next message: Warren W. Gay VE3WWG: "Re: For the AdaOS folks"
- Previous message: Dmitry A. Kazakov: "Re: For the AdaOS folks"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 31 Dec 2004 12:07:05 +0100 To: comp.lang.ada@ada-france.org
Consider the following version of the Rosen trick. Should
A_Type be returned by reference or by copy? GNAT 3.15p says:
by reference; more recent versions of GNAT say: by copy. My
understanding is that it should be by reference, because it
has a component R_Type that is a return_by_reference type
(R_Type is return_by_reference because the full view is limited
private).
GNAT 3.15p gives the expected output:
Mechanism: 2 <= GNAT specific, means return_by_reference
0
1
1
2
gcc at the pre-ssa tag gives:
Mechanism: 1 <= GNAT specific, means return_by_copy
0
0
1
1
Before reporting this bug I would like to be sure that it is one.
Language lawyers, please step forwards!
Thanks a lot,
Duncan.
-- B spec --
package B is
type A_Type is limited private;
function Get_The_A return A_Type;
procedure Increment (An_A : A_Type);
procedure Print (An_A : A_Type);
private
type R_Type (An_A : access A_Type) is limited null record;
type A_Type is record
R : R_Type (A_Type'Access);
I : Integer := 0;
end record;
end;
-- B body --
with Ada.Text_IO; use Ada.Text_IO;
package body B is
The_A : A_Type;
function Get_The_A return A_Type is
begin
return The_A;
end;
procedure Increment (An_A : A_Type) is
begin
An_A.R.An_A.I := An_A.R.An_A.I + 1;
end;
procedure Print (An_A : A_Type) is
begin
Put_Line (An_A.I'Img);
end;
end;
-- X --
with Ada.Text_IO; use Ada.Text_IO;
with B; use B;
procedure X is
procedure Look is
The_A_Reference : A_Type renames Get_The_A;
begin
Print (The_A_Reference);
Increment (The_A_Reference);
Print (The_A_Reference);
end;
begin
Put_Line ("Mechanism:" & Integer'Image (Get_The_A'Mechanism_Code)); -- GNAT specific attribute, 1 = by_copy, 2 = by_reference
New_Line;
Look;
New_Line;
Look;
end;
- Next message: Warren W. Gay VE3WWG: "Re: For the AdaOS folks"
- Previous message: Dmitry A. Kazakov: "Re: For the AdaOS folks"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|