簡體   English   中英

這是MSVC ++編譯器的錯誤嗎?

[英]Is this a MSVC++ compiler bug?

我想我可能在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() };

這真的是一個編譯器錯誤嗎? 謝謝。

是的,這是編譯器中的一個錯誤。 無論代碼是否格式良好,所有編譯器崩潰都是編譯器錯誤。 11月在Microsoft Connect上報告了此特定錯誤:

內部編譯器錯誤與std :: map操作和返回語句中的大括號。

在這個bug中,Xiang報告說我們已經為下一個主要版本的編譯器解決了這個問題(我已經驗證了你的代碼使用最新的內部版本編譯)。 與此同時,建議的解決方法是執行您已完成的操作並在return語句中命名類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM