[webkit-dev] Style guideline on initializing non-POD types via member initialization

Filip Pizlo fpizlo at apple.com
Thu Mar 14 13:06:03 PDT 2019


I like to draw this distinction: is the initializer a constant?

It’s not a constant if it relies on arguments to the constructor. “This” is an argument to the constructor. 

It’s also not a constant if it involves reading the heap. 

So, like you, I would want to see this code done in the constructor. But I’m not sure that my general rule is the same as everyone’s. 

-Filip

> On Mar 14, 2019, at 12:59 PM, Simon Fraser <simon.fraser at apple.com> wrote:
> 
> I've seen some code recently that initializes non-POD members via initializers. For example, SVGAElement has:
> 
>    AttributeOwnerProxy m_attributeOwnerProxy { *this };
> 
> I find this a little disorientating, and would normally expect to see this in the constructor as m_attributeOwnerProxy(*this), as it makes it easier to find places to set breakpoints, and the ordering of initialization is easier to see.
> 
> Are people OK with this pattern, or should we discourage it via the style guidelines (and style checker)?
> 
> Simon
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev


More information about the webkit-dev mailing list