Default member initializers (or non-static data member initializers if you like) are these things: struct Foo { int x = -1; int y = 0xdeadbeef; }; I'd like to use them, because I'm tired of updating out-of-line constructors to explicitly initialize all scalar members. See for example CodeGenFunction(): http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?revision=235664&view=markup#l37 This feature is supported by MSVC 2013, Clang 3.0, and GCC 4.7, which together represent our platform support floor. Any objections? If not, I'll update http://llvm.org/docs/CodingStandards.html in a few days. I'll also put in a word recommending that these should only be used to initialize scalars to constant values. C++ is very flexible and will let you put lots of stuff here, but doing so is probably bad form. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150428/b1dbb911/attachment.html>
On Tue, Apr 28, 2015 at 2:41 PM, Reid Kleckner <rnk at google.com> wrote:> Default member initializers (or non-static data member initializers if you > like) are these things: > struct Foo { > int x = -1; > int y = 0xdeadbeef; > }; > > I'd like to use them, because I'm tired of updating out-of-line > constructors to explicitly initialize all scalar members. See for example > CodeGenFunction(): > > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?revision=235664&view=markup#l37 > > This feature is supported by MSVC 2013, Clang 3.0, and GCC 4.7, which > together represent our platform support floor. > > Any objections? If not, I'll update > http://llvm.org/docs/CodingStandards.html in a few days. > > I'll also put in a word recommending that these should only be used to > initialize scalars to constant values. C++ is very flexible and will let > you put lots of stuff here, but doing so is probably bad form. >+1 Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150428/7cd047a7/attachment.html>
> On Apr 28, 2015, at 2:41 PM, Reid Kleckner <rnk at google.com> wrote: > > Default member initializers (or non-static data member initializers if you like) are these things: > struct Foo { > int x = -1; > int y = 0xdeadbeef; > }; > > I'd like to use them, because I'm tired of updating out-of-line constructors to explicitly initialize all scalar members. See for example CodeGenFunction(): > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?revision=235664&view=markup#l37 <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?revision=235664&view=markup#l37> > > This feature is supported by MSVC 2013, Clang 3.0, and GCC 4.7, which together represent our platform support floor. > > Any objections? If not, I'll update http://llvm.org/docs/CodingStandards.html <http://llvm.org/docs/CodingStandards.html> in a few days. > > I'll also put in a word recommending that these should only be used to initialize scalars to constant values. C++ is very flexible and will let you put lots of stuff here, but doing so is probably bad form.SGTM. -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150428/688cd0eb/attachment.html>
On Tue, Apr 28, 2015 at 11:45 PM Reid Kleckner <rnk at google.com> wrote:> > I'll also put in a word recommending that these should only be used to > initialize scalars to constant values. C++ is very flexible and will let > you put lots of stuff here, but doing so is probably bad form. >Agreed, especially in LLVM project. And MSVC has problems with complex initializers: https://connect.microsoft.com/VisualStudio/feedback/details/807232/class-member-vector-initialization-list-unexpected-c-11 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150428/e76fce4f/attachment.html>
Thanks! I updated the coding standards in r236244. On Tue, Apr 28, 2015 at 2:41 PM, Reid Kleckner <rnk at google.com> wrote:> Default member initializers (or non-static data member initializers if you > like) are these things: > struct Foo { > int x = -1; > int y = 0xdeadbeef; > }; > > I'd like to use them, because I'm tired of updating out-of-line > constructors to explicitly initialize all scalar members. See for example > CodeGenFunction(): > > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?revision=235664&view=markup#l37 > > This feature is supported by MSVC 2013, Clang 3.0, and GCC 4.7, which > together represent our platform support floor. > > Any objections? If not, I'll update > http://llvm.org/docs/CodingStandards.html in a few days. > > I'll also put in a word recommending that these should only be used to > initialize scalars to constant values. C++ is very flexible and will let > you put lots of stuff here, but doing so is probably bad form. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150430/7206438d/attachment.html>