
Optimizing C++ Const Objects in LLVM - jjuhl
https://docs.google.com/document/d/112O-Q_XrbrU1I4P-oiLCN9u86Qg_BYBdcDsmh7Pn9Nw/mobilebasic
======
ape4
So it seems 'const' has gone the way of 'register' \- ignored by the compiler.

~~~
JoeAltmaier
Just the optimizer. The compiler still enforces it as it reads the code.

~~~
wyldfire
I'd guess that the optimizer can't really count on it because it could get
aliased by code the optimizer can't see and then casted away.

~~~
jjuhl
Yeah. const_cast (and C-style casts) and mutable existing in the language make
const pretty useless to the optimizer. But at least they are trying to get
some benefit from it in some cases. A C++ variant (compiler flag) that would
remove const_cast, mutable and the cast-const-away parts of C-style casts from
the language and allow the optimizer to put more value into 'const' could be
interresting.

~~~
pcwalton
ISO Core C++ is trying to do something like this. They have to, in order to
count on the properties of "const" for their static safety analysis.

(I have my reservations about whether ISO Core C++ with the lifetime profile
really qualifies as C++ anymore due the massively backwards incompatible
nature of the changes, but it'll be interesting nonetheless.)

~~~
twoodfin
Can you link to more information about this? Googling for "c++ core lifetime
profile" just takes me to the Core Guidelines.

Is the idea that they'll codify a bunch of static analysis that disallows
problematic constructs & patterns? Could implementers then add something like
Rust's ownership checks (assuming full source visibility)?

~~~
steveklabnik
My sibling commentators have given you good links, but it's worth noting that
these systems and Rust have a lot of differences. For example, they're
explicitly not trying to tackle data races, and the way that they work is
different.

I'm excited to see this all play out though!

