https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96996
--- Comment #6 from Jonathan Wakely ---
const_cast lets you add/remove cv-qualifiers from pointers and references, but
that doesn't make it OK to write to an object that was originally defined as
const. Similar to how reinterpret_cast from int* t
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96996
--- Comment #5 from Matthijs Kooijman ---
> But isn't there const_cast<> to change the value of p?
Yes, that makes it possible to write to a const object, but actually doing so
is undefined behavior (see [dcl.type.cv] I quoted above).
The spec
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96996
--- Comment #4 from Richard Biener ---
But isn't there const_cast<> to change the value of p?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96996
--- Comment #3 from Jonathan Wakely ---
Yes, that's what I said:
> I'm not saying the optimization would be invalid
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96996
--- Comment #2 from Matthijs Kooijman ---
> Replacing non_constant_test with a new object is possible, and allowed. But
> the name "non_constant_test" cannot be used to refer to the new object, so
> any calls to non_constant_ref() after the obj
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96996
Jonathan Wakely changed:
What|Removed |Added
Component|web |c++
Keywords|