c++c++11initializer-listuniform-initializationin-class-initialization

In-class member initialization with an initializer list using uniform initialization syntax?


I am trying to compile the following with MSVC2013:

class SomeClass
{
    struct SomeStruct { bool a,b,c; };
    SomeStruct ss{false, false, false};
}

The compiler gives me the following error: SomeClass::SomeStruct::SomeStruct: no overloaded function takes 3 arguments.

If I change the code to this:

class SomeClass
{
    struct SomeStruct { bool a,b,c; };
    SomeStruct ss{{false, false, false}};
}

the program compiles and runs fine. Is this a problem with the compiler, or do I not understand the syntax? From what I've been reading, the first version should compile.


Solution

  • Here is the responsible grammar from N3797:

    // after a member declaration:
    braced-or-equal-initializer-list:
      = initializer-clause
      braced-init-list
    
    braced-init-list:
      { initializer-list ,OPT }
      { }
    
    initializer-list:
      initializer-clause
      initializer-list, initializer-clause
    
    initializer-clause:
      assignment-expression
      braced-init-list
    

    So I'd say the first statement is correct and it is indeed accepted by a recent gcc and clang.