[PATCH] Remove 'explicit' keyword from constructors with multiple (non-default) arguments.

Arthur O'Dwyer arthur.j.odwyer at gmail.com
Mon Jun 23 11:49:57 PDT 2014


On Mon, Jun 23, 2014 at 11:00 AM, Matt Beaumont-Gay
<matthewbg at google.com> wrote:
> On Mon, Jun 23, 2014 at 4:47 AM, Alexander Kornienko <alexfh at google.com> wrote:
>>
>> +Matt, who requested this feature.
>
> I did not know that 'explicit' had an expanded meaning in C++11. I bet
> that most cases in our codebase where 'explicit' is present on a
> multi-argument ctor are due to arguments being added to a one-argument
> ctor, rather than actively trying to avoid copy-list-initialization.

I would expect that you could complete that thought with
"…and most cases in our codebase where 'explicit' is absent on a
single-argument ctor are due to arguments being removed from a
two-argument ctor."

Is there really a good argument for forbidding multi-argument
'explicit' constructors in your style guide?  IMO it would be
reasonable for a C++11 style guide to treat 'explicit' the same way
that C++03 style guides evolved to treat 'break' in switch statements:
//every// case should have 'break' (or an explanatory comment), and
//every// ctor should have 'explicit' (or an explanatory comment).

(I've never seen a style guide that mandated 'explicit' on every ctor,
but then I've never seen one that prohibited it, either.)

–Arthur




More information about the cfe-commits mailing list