Possible compiler bug in MSVC12 (VS2013) with designated initializer

早过忘川 提交于 2019-12-18 05:44:13

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/24090739/possible-compiler-bug-in-msvc12-vs2013-with-designated-initializer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!