[webkit-dev] Do we have a style preference about const member functions?

Geoffrey Garen ggaren at apple.com
Sat May 28 17:15:45 PDT 2011

This came up in https://bugs.webkit.org/show_bug.cgi?id=59604.

My personal preference is against const member functions because they force many error-prone code changes: introducing a const forces the transitive closure of all potential callees to change their signatures recursively, and if you get this wrong in the case of a virtual function, you introduce a very subtle set of bugs.

I don't see much upside to const member functions because they're just an unenforced convention: sub-object and "mutable" data members are still non-const inside a so-called const function, and you can always const_cast away so-called const-ness, as WebKit currently does in 483 places.


More information about the webkit-dev mailing list