I was reading some code that has been in use for a long time without problems, below I have a simplified version:
void SomeClass::someMethod(const std::string& arg1, const std::string& arg2) {
// unrelated code
const std::string& var = arg1 + arg2;
// var used in other concatenations
// var used to index a map
}
I would have assumed that var
is not safe to use because it references a temporary. The lifetime of the temporary here is too short or does it live until the end of the method?