https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114220

--- Comment #3 from Дилян Палаузов <dilyan.palauzov at aegee dot org> ---
> The warning is designed this way explictly because you are returning a 
> reference and taking a reference as an argument and in the case of b2, the 
> tempory is `std::string("u")` .

> In GCC 14+ (since r14-9263-gc7607c4cf18986), you can add [[gnu::no_dangling]] 
> to the z2 function definition to mark it as not returning a dangling 
> reference (from the arguments). and the warning goes away.

If the declaration and definitions are in different files, do I have to add
[[gnu::no_dangling]] only to the function declaration ?

That said, is the warning triggered only based on the function declaration
(accepting as parameter a reference to temporary and returning a reference),
when on the function invocation the parameter is indeed a reference to a
temporary?

Reply via email to