The senior who left for a startup to 'make it big' left a farewell commit: returning const std::string& instead of by value — 'optimization, fewer copies'. Review was a formality, he's a senior after all. Now user greetings arrive as memory garbage. Fix the signature, then explain at retro why the compiler had been warning all along.
makeGreeting returns a reference to a local variable — the string dies when the function returns, and the caller is left holding a dangling reference (undefined behaviour). Fix the signature so the caller receives a valid string.
makeGreeting must return the string by value (no reference into the dead frame)s when makeGreeting returns?static local a poor "fix" for this bug?The fix is one character class: change the return type from const std::string& to std::string.
Returning a local by value is cheap: the compiler elides the copy (NRVO) or moves it.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.