Allow default member initializers in LLVM

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Allow default member initializers in LLVM

Reid Kleckner-2
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():

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.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Allow default member initializers in LLVM

Eli Bendersky


On Tue, Apr 28, 2015 at 2:41 PM, Reid Kleckner <[hidden email]> 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():

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

 


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Allow default member initializers in LLVM

Chris Lattner-2
In reply to this post by Reid Kleckner-2

On Apr 28, 2015, at 2:41 PM, Reid Kleckner <[hidden email]> 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():

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.

SGTM.

-Chris



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Allow default member initializers in LLVM

Paweł Bylica
In reply to this post by Reid Kleckner-2
On Tue, Apr 28, 2015 at 11:45 PM Reid Kleckner <[hidden email]> 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

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Allow default member initializers in LLVM

Reid Kleckner-2
In reply to this post by Reid Kleckner-2
Thanks! I updated the coding standards in r236244.

On Tue, Apr 28, 2015 at 2:41 PM, Reid Kleckner <[hidden email]> 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():

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.


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev