Gabriel Dos Reis
2015-Mar-15 05:26 UTC
[LLVMdev] 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150314/4d4cc6cc/attachment.html>
Chandler Carruth
2015-Mar-15 05:51 UTC
[LLVMdev] Explicit constructors with more than one argument
On Sat, Mar 14, 2015 at 10:26 PM, Gabriel Dos Reis < gdr at integrable-solutions.net> wrote:> 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};". -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150314/4ccf0474/attachment.html>
Gabriel Dos Reis
2015-Mar-15 08:24 UTC
[LLVMdev] Explicit constructors with more than one argument
On Sat, Mar 14, 2015 at 10:51 PM, Chandler Carruth <chandlerc at google.com> wrote:> > On Sat, Mar 14, 2015 at 10:26 PM, Gabriel Dos Reis < > gdr at integrable-solutions.net> wrote: > >> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150315/7b8c8113/attachment.html>
David Blaikie
2015-Mar-15 16:58 UTC
[LLVMdev] Explicit constructors with more than one argument
On Sat, Mar 14, 2015 at 10:51 PM, Chandler Carruth <chandlerc at google.com> wrote:> > On Sat, Mar 14, 2015 at 10:26 PM, Gabriel Dos Reis < > gdr at integrable-solutions.net> wrote: > >> 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.> > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150315/12bb2360/attachment.html>