【发布时间】:2014-02-05 13:50:40
【问题描述】:
我可能在 GCC v4.8.2 中发现了一个错误,但我想在提交之前先检查一下,因为这可能是我做错了什么!
以下代码:
#include <vector>
struct Message
{
typedef union {
char byte;
const char *str;
} Parameter;
Parameter p1;
Parameter p2;
};
int main()
{
std::vector<Message> messages_;
messages_.push_back({{ .byte = 'a' }});
Message message = {{ .byte = 'a' }, { .str = "Hello World" }};
messages_.push_back(message);
messages_.push_back({{ .byte = 'a' }, { .str = "Hello World" }});
}
clang++ -std=c++11 main.cpp 编译得很好。然而g++ 输出这个:
main.cpp: In function ‘int main()’:
main.cpp:23:66: internal compiler error: in reshape_init_class, at cp/decl.c:5216
messages_.push_back({{ .byte = 'a' }, { .str = "Hello World" }});
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccrf5vwr.out file, please attach this to your bugreport.
如果没有人有任何想法,我会将其作为错误提交,尽管根据我的经验,程序员的问题几乎从来都不是编译器错误,而且几乎总是他自己的错误!
【问题讨论】:
-
Please submit a full bug report已经是答案了 -
内部编译器错误始终是编译器错误。
-
从技术上讲,我认为这应该需要
-std=g++11进行编译,因为指定的初始化程序(或其他任何名称)是 C,而不是 C++。 -
我觉得这和one that has already been reported是一样的bug,如果是这样,不需要重新报告。
-
我已将它作为评论添加到那个:)
标签: c++ gcc c++11 unions compiler-bug