The issue with const_cast is if it’s used on data that is originally defined/declared as const, since the compiler may choose to perform certain optimizations or decisions assuming that data will be read-only. If you use const_cast and then try to modify said data, you run into UB.
View all comments
Show parent comment
5
u/Big-Rub9545 Jul 29 '26
The issue with const_cast is if it’s used on data that is originally defined/declared as const, since the compiler may choose to perform certain optimizations or decisions assuming that data will be read-only. If you use const_cast and then try to modify said data, you run into UB.