Why would this be needed?
With ldc -O3 the test function can be completely erased:
import std;
void main()
{
     Foo foo = new Foo;
     foo.x = 7;
     test(foo);
}
void test(Foo foo) {
     writeln(foo.get);
}
class Foo {
     int x;
     int get() { return x; }
}