Temporaries are always const and no its not safe to constCast it. Zig requires mutable references to always point to a location which clearly implies that it is backed by some sort of storage.
It depends on how many times you reuse the pointer and how deep you hide the @constCast(). The compiler may think it is a good idea to reuse pointer to immutable value for optimization.
Your snippet is unrelated to constCast, but rather showcasing aliasing. constCast is unsafe because the address may not be in writable memory region.
Typically you only use constCast to bypass bad C apis. If you have a address that was obtained from a allocator, that is usually safe to constCast (though you still want to prefer fixing your types instead of relying on constCast)
Yes, this makes sense. I guess what’s missing in Zig is something like a &(int){expression} compound literal in C which explicitly ensures that an object is stored in the stack frame.