[英]VC++ 17 internal compiler error
I have some really weirdly behaving code which makes the compiler crash. 我有一些非常奇怪的行为代码,这些代码会使编译器崩溃。 I am using VC++ 17:
我正在使用VC ++ 17:
//.hpp
typedef unsigned short UID;
typedef UID GoodType;
typedef struct _Recipe
{
typedef struct {
GoodType goodType; unsigned short units;
} GoodRatio;
std::vector<GoodRatio> input;
GoodRatio output;
//int a;
} Recipe;
//.cpp
int main()
{
std::vector<Recipe> recipes
{
{
{ { 0, 1 }, { 1, 2 } }, { 2, 1 }
},
};
}
The error: 错误:
1>c:\users\peter\downloads\nationsgamemockup\nationsgamemockup\nationsgamemockup.cpp(25): fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 255)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
The behaviour I observed so far: 到目前为止,我观察到的行为:
If I uncomment the //int a;
如果我取消注释
//int a;
line the error goes away regardless of whether I add an argument for a in the constructor call in the main function. 不管我是否在主函数的构造函数调用中为a添加参数,错误都会消失。
If I comment the std::vector<GoodRatio> input;
如果我评论
std::vector<GoodRatio> input;
line and remove the corresponding argument from the constructor call the error goes away. 行并从构造函数调用中删除相应的参数,错误就会消失。
If I comment the GoodRatio output;
如果我评论
GoodRatio output;
line and remove the corresponding argument from the constructor call the error goes away. 行并从构造函数调用中删除相应的参数,错误就会消失。
If I change the recipes
variable in main
to just a single recipe
the error goes away (as in simply Recipe a{ { { 0, 1 },{ 1, 2 } },{ 2, 1 } };
). 如果我将
main
的recipes
变量更改为仅一个recipe
该错误就会消失(就像简单的Recipe a{ { { 0, 1 },{ 1, 2 } },{ 2, 1 } };
)。
Note: The _Recipe
struct cannot be an anonymous struct because it has a data member of type std::vector<GoodRatio>
and the Recipe::GoodRatio
type only comes into existence at the semicolon after the typedef. 注意:
_Recipe
结构不能是匿名结构,因为它具有类型为std::vector<GoodRatio>
的数据成员,并且Recipe::GoodRatio
类型仅在typedef之后的分号处出现。 That is my guess at least. 至少这是我的猜测。 I get an error if I try to do this.
如果尝试执行此操作,则会出现错误。
Edit: My question is: Why does this happen? 编辑:我的问题是:为什么会发生这种情况?
Adding a constructor to GoodRatio seems to solve the problem: 向GoodRatio添加构造函数似乎可以解决此问题:
GoodRatio(unsigned short goodType = {}, unsigned short units = {}) :
goodType{ goodType }, units{ units } {}
I have also sent feedback to microsoft. 我还向Microsoft发送了反馈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.