2014-01-26 127 views
7

我想我可能在VS2013附带的MSVC++编译器中发现了一个编译器错误,但这是一个我不能确定的简单情况。再加上我仍在学习C++的事实,我想在提交任何内容之前先在这里提问;因为老实说,我很确定这只是我做错了事导致了一个不寻常的错误信息。这是一个MSVC++编译器错误?

反正我在一个小测试文件,减少了问题:

#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() };

这真的是一个编译器错误吗?谢谢。

+11

我会说'编译器内部错误总是值得报告,无论使用的源代码。 – GSerg

+4

当编译器指出这是一个编译器错误时,那么它就是编译器中的一个错误,或者说它是编译器中的一个错误。在这两种情况下,这是一个编译器错误:-) –

+1

哈哈,好点,GSerg和Torsten ... :) – Xenoprimate

回答

7

是的,这是编译器中的一个错误。无论代码是否格式良好,所有编译器崩溃都是编译器错误。这种特定的错误报道微软Connect在十一月:

Internal compiler error with std::map operations and braces in return statement.

在bug,翔报道,我们已经修正了这个问题,编译器的下一个主要版本(我已经确认您的代码编译使用最新的内部构建)。与此同时,推荐的解决方法是完成您所做的并在返回语句中命名该类型。

+0

嗨,詹姆斯,感谢您的回复。 :)在我留下的评论鼓励了我之后,我已经在MS Connect上提出了一个错误;所以我想它应该被标记为重复。 https://connect.microsoft.com/VisualStudio/feedback/details/814718/msvc-compiler-error – Xenoprimate

+1

谢谢。我们会将其解决为重复。错误报告多次比完全没有更好。 :-) –

+0

我在阅读http://connect.microsoft.com/VisualStudio/feedback/details/808852/internal-compiler-error-with-std-map-operations-and-braces-in-return-statement和它应该是固定的,但我仍然有同样的问题。 –