| 1 |
// PR c++/113256 |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
// { dg-options "-Wdangling-reference" } |
| 4 |
// { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } |
| 5 |
|
| 6 |
#include <utility> |
| 7 |
#include <cassert> |
| 8 |
|
| 9 |
template<class M, class T, class A> auto bind(M T::* pm, A) |
| 10 |
{ |
| 11 |
return [=]( auto&& x ) -> M const& { return x.*pm; }; |
| 12 |
} |
| 13 |
|
| 14 |
template<int I> struct arg {}; |
| 15 |
|
| 16 |
arg<1> _1; |
| 17 |
|
| 18 |
int main() |
| 19 |
{ |
| 20 |
std::pair<int, int> pair; |
| 21 |
int const& x = bind( &std::pair<int, int>::first, _1 )( pair ); // { dg-bogus "dangling reference" } |
| 22 |
assert( &x == &pair.first ); |
| 23 |
} |