Is the following C++ code well-formed?
void consumer(char const* p) { std::printf("%s", p); } std::string random_string_generator(); consumer(random_string_generator().c_str()); The problem I have with it is, that after creating the temporary std::string object and taking the c_str() pointer, nothing prevents the std::string object from getting destroyed, unless I'm wrong.
Is this code well-formed according to the standard? It does work, when I test with g++.