A regular string string literal has the following definition:
Ordinary string literals and UTF-8 string literals are also referred to as narrow string literals. A narrow string literal has type “array of n const char”, where n is the size of the string as defined below, and has static storage duration (3.7).
I'm assuming because it has static storage duration and that they're typically placed in ROM, it really isn't a big deal if there's a dangling reference to it. The following code emits a warning
const char* const & foo()
{
return "Hello";
}
// warning: returning reference to temporary [-Wreturn-local-addr]
But this is fine, even without the static keyword
const char* const & foo()
{
const char* const & s = "Hello";
return s;
}
So what is the difference between the two?