Yeah, I’ve now done as much as I can using allocatables.
But the problem really was that I allocated memory in a constructor (via some c library call) which I wanted to release in the FINAL routine. In that case, the FINAL routine executed when cleaning up the temporary RHS object before assignment already had the reference for the allocated object. It cleared that memory so it was undefined when I actually wanted to access it from the newly constructed object assigned to the LHS.
The solution, as it seems, is not to allocate that memory in the constructor but elsewhere after construction, and IF
-guard its deallocation in the final routine. Not so elegant but at least it works.