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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
const std::string& z2(const std::string& m);

const std::string& z2(const std::string& m) { return hashTable2.at(m); }


  const std::string& b2 { z2("u") };


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.

Reply via email to