11

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

diapir
  • 2,872
  • 1
  • 19
  • 26
  • Is this example minimal (i.e. does the problem go away if you remove some members of these `struct`s)? – Patrick Collins Jun 06 '14 at 21:20
  • 2
    In case you didn't see it in the link: *A fix for this issue has been checked into the compiler sources. The fix should show up in the future release of Visual C++.* Perhaps this works with the new CTP? – chris Jun 06 '14 at 21:23
  • @PatrickCollins This is a simplified example, the error first showed with `D2D1_SIZE_U` and `D2D1_HWND_RENDER_TARGET_PROPERTIES` from – diapir Jun 06 '14 at 21:23
  • @chris Just saw. The link seemed dead on my side of the internet. Thanks. – diapir Jun 06 '14 at 21:34

1 Answers1

9

It is a known bug. It is said to be fixed in the next version of MSVC.

EDIT: Unfortunately, the bug is still present in VS14 CTP 4.

EDIT: This bug has been fixed in VS2015 CTP 5.

diapir
  • 2,872
  • 1
  • 19
  • 26