Explicit constructors with more than one argument

Hi,

Some LLVM classes (e.g. ReturnInst) have explicit constructors with at least two parameters (with no default arguments). Why is that? E.g. what are they trying to prevent?

– Gaby

FWIW, I suspect that it is mostly an accident (IE, one of the arguments was
added without removing the explicit or a default was removed, etc.)

However, there are good reasons for this in C++11 -- making constructors
explicit prevents them from being called in return statements like "return
{a, b};".

Hi,

Some LLVM classes (e.g. ReturnInst) have explicit constructors with at
least two parameters (with no default arguments). Why is that? E.g. what
are they trying to prevent?

-- Gaby

FWIW, I suspect that it is mostly an accident (IE, one of the arguments
was added without removing the explicit or a default was removed, etc.)

OK, that sounds like it; thanks.

However, there are good reasons for this in C++11 -- making constructors
explicit prevents them from being called in return statements like "return
{a, b};".

Err, if I can have "return T(a, b);", I am curious about what mistakes (in
LLVM codebase) are being prevented by refusing "return { a, b };" -- I tend
to write mostly only the brace these days, so I'm curious about where the
potholes are.

-- Gaby

Hi,

Some LLVM classes (e.g. ReturnInst) have explicit constructors with at
least two parameters (with no default arguments). Why is that? E.g. what
are they trying to prevent?

-- Gaby

FWIW, I suspect that it is mostly an accident (IE, one of the arguments
was added without removing the explicit or a default was removed, etc.)

However, there are good reasons for this in C++11 -- making constructors
explicit prevents them from being called in return statements like "return
{a, b};".

Yeah, my current take on it is: yeah, some 'explicit' on multi-arg ctors is
probably accidental, but it's not pointless so removing it isn't entirely
trivial. But adding explicit to every no-arg ctor you don't want to call
with braced init seems... painfully verbose, so I've not taken a strong
stance that we should do that either.

And I /think/ MSVC still doesn't support braced init, so it's all a bit of
an abstract debate for the LLVM codebase for now anyway.

Hi,

Some LLVM classes (e.g. ReturnInst) have explicit constructors with at
least two parameters (with no default arguments). Why is that? E.g. what
are they trying to prevent?

-- Gaby

FWIW, I suspect that it is mostly an accident (IE, one of the arguments
was added without removing the explicit or a default was removed, etc.)

However, there are good reasons for this in C++11 -- making constructors
explicit prevents them from being called in return statements like "return
{a, b};".

Yeah, my current take on it is: yeah, some 'explicit' on multi-arg ctors
is probably accidental, but it's not pointless so removing it isn't
entirely trivial. But adding explicit to every no-arg ctor you don't want
to call with braced init seems... painfully verbose, so I've not taken a
strong stance that we should do that either.

And I /think/ MSVC still doesn't support braced init, so it's all a bit of
an abstract debate for the LLVM codebase for now anyway.

Right.
Based on the VS2015 CTP6 release, I suspect we can assume that VS2015 will
support uniform initialization.

-- Gaby

MSVC 2013 supports braced init, I'm using it in clang already and so far it seems to work.

- Ben