On 15/07/16 02:06, Jesse Phillips wrote:
On Thursday, 14 July 2016 at 18:49:36 UTC, Steven Schveighoffer wrote:
If what you wrote is UB (as it is in D), then the compiler can go
ahead and assign 5 to y.

In C++, the compiler has to reload x, because it may have changed.

Someone explained this to me recently on the NG.

-Steve

Thanks, so when people say "C++ defines the behavior of modifying const"
what they really mean is "C++ defines const as meaningless."

Const is very far from meaningless in C++. It is an extremely valuable tool in turning bugs into compile time errors. That is not something to think lightly of (and, sadly, not something D does very well)

In terms of optimizations, there are, indeed, cases where, had const not been removable, things could be optimized more. I don't think D has a right to complain about C++ in that regard, however.

Also, see http://stackoverflow.com/questions/25029516/c-reliance-on-argument-to-const-reference-not-changing

Shachar

Reply via email to