__traits(isRef, this) cannot distinguish l-value- from r-value-passed this
Nordlöw via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 18 16:44:51 PST 2017
A compilation of
struct T
{
int x;
@disable this(this); // this has no effect on the issue
ref inout(T) memberFun() inout
{
pragma(msg, "memberFun:", __traits(isRef, this) ? "ref" :
"non-ref", " this");
return this;
}
}
void freeFun()(auto ref const T x)
{
pragma(msg, "freeFun:", __traits(isRef, x) ? "ref" :
"non-ref", " this");
}
unittest
{
T t;
freeFun(t); // `param` passed by reference
freeFun(T.init); // `param` passed by move
t.memberFun(); // `this` passed by what?
T.init.memberFun(); // `this` passed by what?
}
currently prints
memberFun:non-ref this
freeFun:ref this
freeFun:non-ref this
That is, we cannot distinguish an l-value-call to `memberFun`
from an r-value-call. Opposite to what we can when combining
`auto ref`-parameters with `__traits(isRef)` as shown with
function `freeFun` in the code example above.
Disabling the postblit has no effect on the issue.
I need this for enabling efficient delayed evaluation for unary
and binary arithmetic operators in my GNU MP wrapper described
earlier at
http://forum.dlang.org/thread/plqysfanwuoiuslfywyx@forum.dlang.org
Any clues on how to retrieve this information?
More information about the Digitalmars-d-learn
mailing list