-preview=in might break code

kinke noone at nowhere.com
Sun Oct 4 21:38:48 UTC 2020


As for the callee, the only significant change OTOH (except for 
non-PODs not getting copy-constructed/postblitted and destructed) 
would be that it cannot make any assumptions about the address of 
an `in` param (but there's `traits(isRef)` in the presumably 
extremely rare cases one needs to know whether it was passed by 
ref or value):

void foo(T)(in T a, in T b)
{
     assert(&a != &b);
}

void test(T)()
{
     T x;
     foo(x, x);
}

void main()
{
     test!int(); // succeeds - the tiny int is passed as 2 
distinct values
     test!(int[64])(); // fails - the same large array is passed 
by ref
}

---

Once a program conforms to these new semantics, especially wrt. 
to aliasing as mentioned earlier, the compiler- and 
target-specific implementation details and differences don't 
matter.


More information about the Digitalmars-d mailing list