I just came across a something from the fmt library in the format_int class. It has a char buffer member such that when you invoke the class stack space is allocated on the stack in the calling method. You can return a char * from format_int and it remains valid even after the class has been destructed. While std::string also has a c_str member which may return stack memory, the destructor for std::string clears this memory forcing the user to make use of it during the object lifetime. So in comparison short lived std::string objects force you to use the results of c_str before the object is destructed, while format_int lets you use the formatted buffer for the remainder of the function.
Does c++ guarantee that the stack will not be reused until the end of the function, is it safe to hold onto the buffer from the format_int class for the lifetime of the calling function (beyond the lifetime of the format_int object)? Is this behavior a quirk with my compiler (MSVC)?
ps. I get that holding onto the memory is pretty sneaky, I'm just curious if in the real world a compiler would reuse the stack, or if the language forbids that behavior.