[webkit-dev] On returning mutable pointers from const methods
Maciej Stachowiak
mjs at apple.com
Mon Oct 29 08:09:31 PDT 2012
On Oct 29, 2012, at 3:47 PM, Antti Koivisto <koivisto at iki.fi> wrote:
> I don't think the original proposal was meant to apply to the basic container types. Would this be a sensible rule to adopt for WebCore only for example?
>
> Like all our "blanket rules", this one should be ignored when it doesn't make sense. If that kind of cases are expected to be very rare then their existence shouldn't be a show stopper for adopting the rule.
At the moment, I can't think of any obvious counter-examples to the rule other than basic container types. I don't have a problem with the rule in general as long as we acknowledge the exceptions. If we wanted to enforce the rule mechanically, then we could just whitelist the relevant basic data structure types. The same rule should probably also apply to references (and references to pointers).
I think when describing the rule, we should also identify the underlying motivation: "don't expose mutable state from a const member function" in addition to the concrete method used to avoid that goal. That would help avoid misunderstanding over time about the purpose of the rule.
Cheers,
Maciej
More information about the webkit-dev
mailing list