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
pull/1573/head
Herb Sutter 6 years ago committed by GitHub
parent 2eb8ea9279
commit 6e72adc0fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11780,7 +11780,7 @@ for example.)
##### Reason
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

Loading…
Cancel
Save