https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113256
Bug ID: 113256
Summary: False -Wdangling-reference positive
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pdimov at gmail dot com
Target Milestone: ---
The following code
```
#include <utility>
#include <cassert>
template<class M, class T, class A> auto bind( M T::* pm, A a )
{
return [=]( auto&& x ) -> M const& { return x.*pm; };
}
template<int I> struct arg {};
arg<1> _1;
int main()
{
std::pair<int, int> pair;
int const& x = bind( &std::pair<int, int>::first, _1 )( pair );
assert( &x == &pair.first );
}
```
(https://godbolt.org/z/a555MMTqo)
(reduced from a Boost.Bind test case)
causes
```
<source>:16:16: warning: possibly dangling reference to a temporary
[-Wdangling-reference]
16 | int const& x = bind( &std::pair<int, int>::first, _1 )( pair );
| ^
```
with GCC 13.2 (but not trunk).
There are indeed two temporaries created in that full expression, but `int
const&` can't possibly bind to any of them.