Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
712 views
in Technique[技术] by (71.8m points)

c - Possible compiler bug in MSVC12 (VS2013) with designated initializer

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...