function returning std::string crashes without return statement, unlike a function returning int without return statement
问题 #include <iostream> #include <string> using namespace std; string crash() { } int noCrash() { } int main() { crash(); // crashes // noCrash(); // doesn't crash return 0; } The function crash(), crashes with Mingw g++ 4.6.2 and the function noCrash() executes with no issues. Why does the function returning string crash without a return statement? 回答1: Both are undefined behaviors, even noCrash can crash. 回答2: From standard 6.6.3/2 A return statement without an expression can be used only in