I wonder if this line creates a dangling pointer:
string arg="derp";
throw std::runtime_error("Unknown argument "+arg);
Does std::runtime_error copy the string, or does it store the reference?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
std::exception(whichstd::runtime_errorinherits from) must make a copy of the message, even if that’s not called out in the standard explicitly (that I can find). There’s no reason for theexceptionclass to expect that the source of thewhat()message will outlive it in the general case.