Casting away const isn't undefined behavior, but modifying a constant is (#1509)

* Casting away const isn't undefined behavior, but modifying a constant is

You can cast away `const` as much as you like, as long as you never write to variable.

* rewording for clarification
This commit is contained in:
Herb Sutter
2020-01-30 11:28:19 -08:00
committed by GitHub
parent 2eb8ea9279
commit 6e72adc0fe

View File

@@ -11780,7 +11780,7 @@ for example.)
##### Reason ##### Reason
It makes a lie out of `const`. It makes a lie out of `const`.
If the variable is actually declared `const`, the result of "casting away `const`" is undefined behavior. If the variable is actually declared `const`, modifying it results in undefined behavior.
##### Example, bad ##### Example, bad