----
struct S
{
 void foo();
}
void bar(S);

void main()
{
 auto r = new S;
 r.foo();
 bar(r);  //derp
 r.bar(); //derp
};
----

bar(r) would need D to support an implied conversion of S* to S (or to ref S with bar having a reference parameter if you wanted to avoid copying), for this to work.

Converting S* to ref S (without copying) is an interesting idea for D. I wonder what those close to the definition of D and the compiler think of it.

It seems that the following discussion is relevant to the above.

"Why can't we have reference variables"
http://forum.dlang.org/thread/ruwapnhkuvozitefz...@forum.dlang.org

A conservative viewpoint is that converting S* to ref S at the point of call requires that the pointer is valid (because non-pointer variables always work properly as a part of the way the language is defined), and there's no way that the compiler can simply verify that this is so. Therefore, such a conversion should be the programmers responsibility and not be done implicitly.

Carl.

Reply via email to