If the object was originally const, the UB had already occurred?
From what I understand forming a non-const pointer/reference to an actually-const object is fine. Its only the actual modification of said actually-const object that is UB.
I think your second comment is more correct; UB only occurs on the actual modification, so while calling a non-const method on an actually-const object is not itself UB that's probably around where a bugfix would land.
...Well, maybe barring some oddball setup with a non-const method that uses some other criteria to determine whether it's safe to modify whatever it's called on, but I'd hope that kind of thing is relatively rare.
View all comments
Show parent comment
2
u/kisielk Jul 29 '26
It's fine if the thing is actually const, it's not fine if you then modify that that thing through the resulting non-const pointer.