Debian Codegraph @

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

raw
1 // PR c++/106393
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-Wdangling-reference" }
4
5 struct A {
6 int ar[4];
7 int& operator[](int i) { return ar[i]; }
8 };
9 const int &r = A()[2]; // { dg-warning "dangling reference" }
10
11 struct S {
12 const S& self () { return *this; }
13 };
14 const S& s = S().self(); // { dg-warning "dangling reference" }
15
16 struct G {
17 const G& g() { return *this; }
18 };
19
20 struct F {
21 int i;
22 G& f();
23 };
24
25 const G& g = F().f().g(); // { dg-warning "dangling reference" }