Skip to content

Commit 6e72adc

Browse files
authored
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
1 parent 2eb8ea9 commit 6e72adc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

CppCoreGuidelines.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11780,7 +11780,7 @@ for example.)
1178011780
##### Reason
1178111781

1178211782
It makes a lie out of `const`.
11783-
If the variable is actually declared `const`, the result of "casting away `const`" is undefined behavior.
11783+
If the variable is actually declared `const`, modifying it results in undefined behavior.
1178411784

1178511785
##### Example, bad
1178611786

0 commit comments

Comments
 (0)