On Oct 25, 2012, at 12:48 PM, Andreas Kling <[email protected]> wrote:

> 
> So, I propose that we allow only these two signature formats for raw pointers:
> 
> - const Foo* foo() const;
> - Foo* foo();
> 
> Moreover, for methods that return references to objects where call sites are 
> expected to take a strong reference, we should really be using 
> PassRefPtr<Foo> as the return type.
> 
> Thoughts? Objections? Am I missing something?

I am not sure a blanket rule is correct. If the Foo* is logically related to 
the object with the foo() method and effectively would give access to mutable 
internal state, then what you say is definitely correct. But if the const 
object is a mere container that happens to hold pointers, there's no particular 
reason it should turn them into const pointers. For example, it is fine for 
const methods of HashSet or Vector to return non-const pointers if that happens 
to be the template parameter type. In such cases, constness of the container 
should only prevent you from mutating the container itself, not from mutating 
anything held in the container, or else const containers of non-const pointers 
(or non-const types in general) would be useless.

I can see how a blanket rule may be easier to enforce, but we may need to 
actually make judgment calls about logical constness.

Regards,
Maciej



_______________________________________________
webkit-dev mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-dev

Reply via email to