https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103827
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jan Hubicka from comment #4) > What about escape bits? Is it OK to save the address to global memory > and then check it in the destructor? Yes, but does that matter? After the function returns the pointer is invalid and can't be used for anything. It's just an invalid pointer value that happens to be correctly aligned for the parameter type. > I suppose it makes no sense to return a pointer since it will be > available only after end of lifetime? The function can return a pointer to the parameter, but that pointer can't be dereferenced. > OK, what about having const reference? const std::string &s? I'm not sure what you're asking here. It's valid to do a const_cast and modify the string in that case, unless it is bound to an object defined as const. #include <string> extern int foo (const std::string& s); int main() { foo(""); // OK, reference binds to non-const temporary const std::string s; foo(s); // undefined } int foo (const std::string& s) { const_cast<std::string&>(s) = "I am long string over 15 chars"; return s.size(); } I don't think the caller can infer anything about the function body from the function's declaration.