Possible compiler bug in MSVC12 (VS2013) with designated initializer
        Posted  
        
            by 
                diapir
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by diapir
        
        
        
        Published on 2014-06-06T21:16:33Z
        Indexed on 
            2014/06/07
            3:26 UTC
        
        
        Read the original article
        Hit count: 264
        
Using VS2013 Update 2, I've stumbled on some strange error message :
// test.c
int main(void)
{
    struct foo {
        int i;
        float f;
    };
    struct bar {
        unsigned u;
        struct foo foo;
        double d;
    };
    struct foo some_foo = {
        .i = 1,
        .f = 2.0
    };
    struct bar some_bar = {
        .u = 3,
// error C2440 : 'initializing' : cannot convert from 'foo' to 'int'
        .foo = some_foo,
        .d = 4.0
    };
// Works fine
    some_bar.foo = some_foo;
    return 0;
}
Both GCC and Clang accept it.
Am I missing something or does this piece of code exposes a compiler bug ?
EDIT : Duplicate: Initializing struct within another struct using designated initializer causes compile error in Visual Studio 2013
© Stack Overflow or respective owner