I think I might have found a compiler bug in the MSVC++ compiler that comes with VS2013, but it's such a simple case I can't be sure. Coupled with the fact that I'm still learning C++ I wanted to ask here before I submit anything; because honestly I'm pretty sure it'll just be something I'm doing wrong resulting in an unusual error message.
Anyway, I reduced the problem in to a small test file:
#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();
}
When I try to compile that, I get the following error:
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.
To work around the problem I can just specify the type on line six, so that:
return { temp.begin(), temp.end() };
becomes
return std::wstring { temp.begin(), temp.end() };
.
Is this really a compiler bug? Thank you.
Microsoft C++ Compiler (MSVC) This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows.
More precisely, the default path where you'll find the compiler is C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin .
Microsoft C/C++ (MSVC) is a C and C++ compiler that, in its latest versions, conforms to some of the latest C language standards, including C11 and C17.
Is MinGW (MinGW-64) better than Cygwin in terms of MSVC alternative for creating Windows application? If your program will run only on Windows, then MinGW is likely the better choice. MinGW is designed to create Windows applications. It doesn't require users to install additional software to run your application.
Yes, this is a bug in the compiler. All compiler crashes are compiler bugs, regardless whether the code is well-formed. This particular bug was reported on Microsoft Connect in November:
Internal compiler error with std::map operations and braces in return statement.
In the bug, Xiang reports that we have fixed this issue for the next major release of the compiler (and I've verified that your code compiles using the latest internal build). In the meantime, the recommended workaround is to do what you've done and name the type in the return statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With