[Bug c++/96996] Missed optimzation for constant members of non-constant objects

2020-09-10 Thread redi at gcc dot gnu.org
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

[Bug c++/96996] Missed optimzation for constant members of non-constant objects

2020-09-10 Thread matthijs at stdin dot nl
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

[Bug c++/96996] Missed optimzation for constant members of non-constant objects

2020-09-10 Thread rguenth at gcc dot gnu.org
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?

[Bug c++/96996] Missed optimzation for constant members of non-constant objects

2020-09-09 Thread redi at gcc dot gnu.org
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

[Bug c++/96996] Missed optimzation for constant members of non-constant objects

2020-09-09 Thread matthijs at stdin dot nl
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

[Bug c++/96996] Missed optimzation for constant members of non-constant objects

2020-09-09 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96996 Jonathan Wakely changed: What|Removed |Added Component|web |c++ Keywords|