MSVC12 (VS2013) 中可能的编译器错误,带有指定的初始值设定项 [英] Possible compiler bug in MSVC12 (VS2013) with designated initializer
本文介绍了MSVC12 (VS2013) 中可能的编译器错误,带有指定的初始值设定项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 VS2013 Update 2,我偶然发现了一些奇怪的错误消息:
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;
}
GCC 和 Clang 都接受它.
Both GCC and Clang accept it.
我是否遗漏了什么或这段代码是否暴露了编译器错误?
Am I missing something or does this piece of code exposes a compiler bug ?
重复:使用指定的初始化程序在另一个结构中初始化结构会导致 Visual Studio 2013 中的编译错误
推荐答案
这是一个已知错误.据说在下一个版本的 MSVC 中会修复.
It is a known bug. It is said to be fixed in the next version of MSVC.
不幸的是,该错误仍然存在于 VS14 CTP 4 中.
Unfortunately, the bug is still present in VS14 CTP 4.
此错误已在 VS2015 CTP 5 中修复.
This bug has been fixed in VS2015 CTP 5.
这篇关于MSVC12 (VS2013) 中可能的编译器错误,带有指定的初始值设定项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文