What guarantees does D 'const' provide, compared to C++?

Torarin torarind at gmail.com
Thu Aug 16 17:51:47 PDT 2012


2012/8/17 Jonathan M Davis <jmdavisProg at gmx.com>
>
> On Friday, August 17, 2012 02:32:01 Mehrdad wrote:
> > > C++ makes no such guarantees, because you're free to cast away
> > > const and modifiy objects
> >
> > Not correct, as far as I understand.
> > C++ only lets you cast away _const references_ to _mutable_
> > objects.
> > If the object happens to have been const _itself_, then that's
> > undefined behavior.
>
> Well, then our understandings on the matter conflict, and I don't know for
> certain which of us is correct.
>
> - Jonathan M Davis


The C++ standard, section 7.1.6.1:

Except that any class member declared mutable (7.1.1) can be modified,
any attempt to modify a const
 object during its lifetime (3.8) results in undefined behavior.

Torarin


More information about the Digitalmars-d mailing list