首页 文章

带有指定初始化程序的MSVC12(VS2013)中可能存在的编译器错误

提问于
浏览
11

使用VS2013 Update 2,我偶然发现了一些奇怪的错误消息:

// 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;
}

GCC和Clang都接受了 .

我错过了什么或这段代码是否暴露了编译器错误?

EDIT : 重复:Initializing struct within another struct using designated initializer causes compile error in Visual Studio 2013

1 回答

  • 9

    这是known bug . 据说它将在下一版MSVC中修复 .

    EDIT: 不幸的是,VS14 CTP 4中仍然存在该错误 .

    EDIT: 此错误已在VS2015 CTP 5中修复 .

相关问题