On Fri, Oct 26, 2012 at 9:06 AM, Peter Kasting <[email protected]> wrote:

> On Fri, Oct 26, 2012 at 8:27 AM, Rik Cabanier <[email protected]> wrote:
>
>> It is valid for a const method to return you a new object ie a const
>> factory object.
>> In that case, const-ness would not be desired.
>>
>
> Not really.  The point of this thread is that such functions may not
> modify an object's state themselves, but they vend access that can be used
> by the caller to modify it.
>
> Consider for example:
>
> Child* Parent::getNewChild() const;
>

> Assuming the Parent doesn't have a list of its children (questionable), we
> can implement this without mutable pointers.  But then a caller can do:
>
> Child* child = parent->getNewChild();
> child->parent->mutate();
>

this would only be possible if that parent object is casting away a 'const'
somewhere or accessing a global non-const object.
Maybe there should be a rule that 'mutable' or 'const_cast' should not be
allowed.


>
> If you generalize this you find there are very, very few cases where a
> const object can vend a non-const pointer that cannot possibly be used to
> change the state of the world the const object sees.  Which is why the rule
> of thumb suggested in this thread is safer and easier than trying to reason
> about individual cases.
>
> PK
>
_______________________________________________
webkit-dev mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-dev

Reply via email to