In the language model of C++ it can't and optimizer is allowed to optimized on this premise. Changing the value is an undefined behavior. Let me be clear, I'm not talking about any existing CPU or real computer. I'm talking about C++ model.
TBH my gut feeling is that this would be best represented on the type system level. But that's obviously not a small thing... And anything would help.
-
-
I would say something like: ``` [[maybe_unused]] auto copy = obj; function_which_cannot_change_obj(); assume(copy == obj); ``` it will see the assumption, so the obj, must stay same, but also the copy is not needed, so it will be compiled away
-
but that's just pure speculation
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.