From: gorgelo@hotmail.com
Subject: Re: Recommendation of safe subset of Ada to use?
Date: Sat, 5 May 2018 14:32:31 -0700 (PDT)
Date: 2018-05-05T14:32:31-07:00 [thread overview]
Message-ID: <9a41b8a3-2ac9-4630-8028-2ba165b0fb0b@googlegroups.com> (raw)
In-Reply-To: <9839db28-b6c6-44c9-9d36-336a39c12f25@googlegroups.com>
G.B. wrote in the other thread the following on this topic:
> 1. Dangling references: Keeping a reference to an object past its lifetime
>
> Ada:
> ***********************************************
> with Ada.Text_IO; use Ada.Text_IO;
>
> procedure jdoodle is
> type Integer_Access is access all Integer;
>
> function Inner(Value : aliased in out Integer) return Integer_Access is
> begin
> return Value'Access;
> end Inner;
>
> function Outer return Integer_Access is
> Value : aliased Integer := 0;
> begin
> return Inner(Value);
> end Outer;
>
> Ptr : Integer_Access := Outer; -- !!! Dangling reference
> begin
> Put_Line("Hello World");
> end jdoodle;
Anything that can be done to prevent the above effect
should be welcome, if it is representative of what the
2012 RM allows. Or is this new *aliased* parameter thing
some I-know-what-I-am-doing Ada?
So, do explicitly *aliased* parameters indeed break all accessiblity
rules of Ada? I noticed that it is mentioned in the RM alongside
parameters that are passed by reference already because their
type is a by-reference type. I'd expect then, that one
would drop *aliased* for those kinds of type, thus
27. with Ada.Text_IO; use Ada.Text_IO;
28.
29. procedure jdoodle2 is
30. type T is tagged
31. record
32. Data : Integer;
33. end record;
34.
35. type T_Access is access all T;
36.
37. function Inner(Value : in out T) return T_Access is
38. begin
39. return Value'Access;
|
>>> non-local pointer cannot point to local object
40. end Inner;
41.
42. function Outer return T_Access is
43. Value : aliased T := T'(Data => 0);
44. begin
45. return Inner(Value);
46. end Outer;
47.
48. Ptr : T_Access := Outer;
49. begin
50. Put_Line("Hello World");
51. end jdoodle2;
The same dangling pointer effect reappears, however, when I put
*aliased* back, for no apparent reason:
function Inner(Value : aliased in out T) return T_Access is
begin
return Value'Access;
end Inner;
next prev parent reply other threads:[~2018-05-05 21:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-05 21:23 Recommendation of safe subset of Ada to use? joakimds
2018-05-05 21:32 ` gorgelo [this message]
2018-05-06 7:43 ` Jeffrey R. Carter
2018-05-06 8:45 ` Niklas Holsti
2018-05-06 8:52 ` gorgelo
2018-05-06 13:15 ` Jere
2018-05-06 13:47 ` Jere
2018-05-06 21:28 ` Brad Moore
2018-05-08 0:19 ` Randy Brukardt
2018-05-08 8:07 ` Simon Wright
2018-05-07 15:54 ` onox
2018-05-08 0:22 ` Randy Brukardt
2018-05-08 0:06 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox