https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109548
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dmalcolm at gcc dot gnu.org, | |rguenth at gcc dot gnu.org --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- David possibly has inputs on how this should be done so the analyzer can do this kind of diagnostic. Generally I'd say we want sth like T * __attribute__ ((return_lifetime(1))) foo (U *p, ...); where we specify the lifetime of the returned referenced object to be the same as a referenced object in the argument list? So yes, the [[gnu::lifetime(this)]] attribution would maybe do that but can the attribute refer to another explicitely named argument as well? Btw, is there an API to std::move the (possibly) allocated string out of the std::string and make it available as C string pointer?