5 ms·
I edited to add a godbolt link, but repeating here: https://godbolt.org/z/7vre49xb1 https://godbolt.org/z/7vre49xb1 In my example, even though `x` is a `const`
by celrod 3y ago
I edited to add a godbolt link, but repeating here: https://godbolt.org/z/7vre49xb1 https://godbolt.org/z/7vre49xb1
In my example, even though `x` is a `const` local, the assembly still shows that it reloads `x` and adds `1` if we assign to it from a non-const local `y`.
- gameman144 3y agoIsn't that expected since 'y' is still non-const though? In your example, I'd expect 'x' to not escape, since a const-cast of it is undefined.
- celrod 3y agoUnfortunately, `x` does escape, merely because we initialized it via assigning to it from a non-const.