DIP23 draft: Fixing properties redux
Steven Schveighoffer
schveiguy at yahoo.com
Tue Feb 5 11:21:06 PST 2013
On Tue, 05 Feb 2013 13:33:35 -0500, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> Walter and I reviewed the discussion and had a long talk. We are very
> seriously considering banning the use of & against a ref result from a
> function (and actually ref parameters and even struct members in @safe
> code). One would still be able to take the address of a field in a class
> because that's assumed to live on the GC heap.
Back to the problem I stated, how does one do this:
ref A foo();
ref A bar();
A *a;
if(condition)
a = &foo();
else
a = &bar();
// use a for a few lines
I can see a possible solution but it's not pretty:
void processA(ref A a)
{
// lines that deal with a here
}
if(condition)
processA(foo());
else
processA(bar());
But this kind of seems hacky. Why should I have to declare a function
just to keep a persistent reference to a return value for the scope of my
function? Not only is is awkward, there is a performance hit in that I
have to call another function.
Note also that this doesn't fix memory issues:
struct S
{
ref S self() {return this;}
}
ref S bad()
{
S s;
return s.self();
}
Which I believe would be valid still with your rules.
-Steve
More information about the Digitalmars-d
mailing list