2014-01-26 128 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和它應該是固定的,但我仍然有同樣的問題。 –