【发布时间】:2014-01-26 16:28:25
【问题描述】:
我想我可能在 VS2013 附带的 MSVC++ 编译器中发现了一个编译器错误,但这是一个简单的案例,我无法确定。再加上我还在学习 C++,我想在提交任何内容之前先在这里问一下;因为老实说,我很确定这只是我做错了导致不寻常的错误消息。
无论如何,我将问题简化为一个小测试文件:
#include <string>
#include <iostream>
std::wstring cstr_to_wstring(const char* cString) {
std::string temp = cString;
return { temp.begin(), temp.end() };
}
int main() {
std::cout << cstr_to_wstring("Hi").c_str();
}
当我尝试编译它时,我收到以下错误:
1>d:\documents\projects\compilerbugtest\compilerbugtest\compilerbugtest.cpp(6): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 227)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
要解决这个问题,我可以在第六行指定类型,这样:
return { temp.begin(), temp.end() };
变成
return std::wstring { temp.begin(), temp.end() };.
这真的是编译器错误吗?谢谢。
【问题讨论】:
-
我想说
An internal error in the compiler总是值得报告,无论使用何种源代码。 -
当编译器声明这是一个编译器错误时,那么它就是编译器中的一个错误,或者说它是一个错误,它是编译器中的一个错误。在这两种情况下,它都是一个编译器错误 :-)
-
哈哈,好点子,GSerg 和 Torsten... :)
-
您的代码使用
g++ (Debian 4.8.2-14) 4.8.2成功编译。然而,当c_str()返回const wchar_t *时,cout以十六进制打印地址值。 -
@nodakai 嗯,就像我说的,我真的是一个 C++ 菜鸟,哈哈。我刚刚使用了我发现的第一个可以编译的函数:)
标签: c++ visual-c++ visual-studio-2013