简体   繁体   English

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

[英]Possible compiler bug in MSVC12 (VS2013) with designated initializer

Using VS2013 Update 2, I've stumbled on some strange error message : 使用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;
}

Both GCC and Clang accept it. GCC和Clang都接受了。

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 编辑:重复: 使用指定的初始化程序在另一个结构中初始化struct会导致Visual Studio 2013中的编译错误

It is a known bug . 这是一个已知的错误 It is said to be fixed in the next version of MSVC. 据说它将在下一版MSVC中修复。

EDIT: Unfortunately, the bug is still present in VS14 CTP 4. 编辑:不幸的是,VS14 CTP 4中仍然存在该错误。

EDIT: This bug has been fixed in VS2015 CTP 5. 编辑:此错误已在VS2015 CTP 5中修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM