https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67795
--- Comment #3 from frankhb1989 at gmail dot com --- (In reply to Markus Trippelsdorf from comment #1) > gcc even warns: > > t.cpp: In function ‘std::experimental::fundamentals_v1::string_view& > erase_left(size_t, std::experimental::fundamentals_v1::string_view&)’: > t.cpp:9:73: warning: function returns address of local variable > [-Wreturn-local-addr] > return static_cast<string_view &>(n != 0 ? (s.remove_prefix(n), s) : s); > ^ And if the diagnostics exist, they are definitely wrong. First, here 's' is a local variable (in sense of C++ terms) indeed, but this is perfectly valid. Note it is a _parameter_ referencing to an object whose lifetime is unknown in the function/block scopes. This should not trigger such warnings. Otherwise the identity functions for pointers/references are always invalid. That's absurd. Second, the "local variable" wording is somewhat misleading. Returning reference to a local variable is generally wrong because the variable is an _automatic object_ and it would be no sense to use the return value to reference an end-of-life object which would cause undefined behavior. Anyway, this is just not the case here.