Title
Value initialization with multiple initializer-list constructors
Status
cd2
Section
9.4.5 [dcl.init.list]
Submitter
Daniel Krügler

Created on 2009-10-20.00:00:00 last changed 178 months ago

Messages

Date: 2010-03-15.00:00:00

[Voted into WP at March, 2010 meeting as part of document N3079.]

Date: 2010-02-15.00:00:00

Proposed resolution (February, 2010):

Change 9.4.5 [dcl.init.list] paragraph 3 as follows:

List-initialization of an object or reference of type T is defined as follows:

  • If the initializer list has no elements and T is a class type with a default constructor, the object is value-initialized.

  • Otherwise, if the initializer list has no elements and T is an aggregate, the initializer list is used to initialize each of the members of T. [Example:

  •   struct A {
        A(std::initializer_list<int>);  // #1
      };
      struct B {
        A a;
      };
      B b { };    // OK, uses #1
      B b { 1 };  // error
    

    end example]

  • If Otherwise, if T is an aggregate...

  • ...

  • [Example:

      struct S {
        S(std::initializer_list<double>);  // #1
        S(std::initializer_list<int>);     // #2
        S();                                     // #3
        // ...
      };
      S s1 = { 1.0, 2.0, 3.0 };            // invoke #1
      S s2 = { 1, 2, 3 };                  // invoke #2
      S s3 = { };                          // invoke #3 (for value-initialization; see above)
    

    end example]

Date: 2009-10-20.00:00:00

It should always be possible to use the new brace syntax to value-initialize an object. However, the current rules make the following example ill-formed because of ambiguity:

    struct S {
      S();
      S(std::initializer_list<int>);
      S(std::initializer_list<double>);
    };
    S s{};    // Ambiguous initializer-list constructor reference,
              // not value initialization.
History
Date User Action Args
2010-03-29 00:00:00adminsetmessages: + msg2714
2010-03-29 00:00:00adminsetstatus: review -> cd2
2010-02-16 00:00:00adminsetmessages: + msg2545
2010-02-16 00:00:00adminsetstatus: drafting -> review
2009-10-20 00:00:00admincreate