https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117509
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2025-01-03
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The code:
```
/* Don't emit a false positive for:
std::vector<int> v = ...;
std::vector<int>::const_iterator it = v.begin();
const int &r = *it++;
because R refers to one of the int elements of V, not to
a temporary object. Member operator* may return a reference
but probably not to one of its arguments. */
|| (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
&& DECL_OVERLOADED_OPERATOR_P (fndecl)
&& DECL_OVERLOADED_OPERATOR_IS (fndecl, INDIRECT_REF))
|| no_dangling_p (TREE_TYPE (fndecl)))
return NULL_TREE;
```
"Member operator* may return a reference but probably not to one of its
arguments."
But it seems like it missed that this could be the temporary which could cause
a dangling.
e.g
```
#include <vector>
int gg()
{
auto &a = *(std::vector<int>{0,1,2,3}.begin());
return a;
}
```
Should cause a warning here. And yes this is definitely a dangling temporary.
As you can see by -O2 optimized gimple dump output:
```
_36 = operator new (16);
MEM <uint128_t> [(char * {ref-all})_36] = 0x3000000020000000100000000;
operator delete (_36, 16);
_8 = *_36;
```