Turning on unsafe references allows in-out references to be used for primitives and value types, meaning a function prototyped like:
void func(const ValueType &inout x)
will pass a reference to the function and not make a copy. This works just fine, but it seems like this should also work for a constant in reference:
void func(const ValueType &in x)
However, a copy will always be made for a value type passed to an in reference, even if the in reference is constant. This construct causes my users confusion, so I took a quick look at trying to modify the code in asCCompiler::PrepareArgument. The solution looks like it would be more complicated than simply changing what PrepareArgument does in response to an in reference. It looks like there are a lot of checks in the compiler that check the reference type and make assumptions about what an argument is allowed to be. Is this an accurate understanding?
It seems like the checks against the reference type in asCCompiler::MoveArgsToStack would also need to be modified, but I don't quite grasp what the new tests would be.
I would appreciate any help, thanks.
(P.S. It would also be nice to have a constant in-out reference be able to construct a temporary object if the argument passed in is found in the parameter type's constructor)