The problem with the following is that the function returns a pointer to a temporary. However it builds and runs fine here, Qt Creator on macOS.
const char* get_str()
{
QByteArray arr("Some text");
return arr.constData();
}
int main()
{
const char *s = get_str();
printf("%s\n", s);
return 0;
}
How can I make it fail? Or is this one of those undefined behavior cases?
I think by doing printf("%s\n", get_str());
we escape the problem, right?