Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wdangling-reference9.C

raw
1 // PR c++/107532
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-Wdangling-reference" }
4
5 #include <functional>
6
7 struct X { int n; };
8
9 struct S {
10 std::reference_wrapper<const X> wrapit() const { return x; }
11 X x;
12 };
13
14 void
15 g (const S& s)
16 {
17 const auto& a1 = s.wrapit().get();
18 (void) a1;
19 const auto& a2 = S().wrapit().get(); // { dg-warning "dangling reference" }
20 (void) a2;
21 }