gcc/testsuite/g++.dg/warn/Wno-return-local-addr.C
raw| 1 | // { dg-do assemble } |
| 2 | // { dg-options "-Wno-return-local-addr" } |
| 3 | |
| 4 | int& bad1() |
| 5 | { |
| 6 | int x = 0; |
| 7 | return x; // { dg-error "cannot bind non-const lvalue reference" "" { target c++23 } } |
| 8 | } |
| 9 | |
| 10 | int* bad2() |
| 11 | { |
| 12 | int x = 0; |
| 13 | return &x; |
| 14 | } |
| 15 | |
| 16 | int f(); |
| 17 | |
| 18 | const int& bad3() |
| 19 | { |
| 20 | return f(); |
| 21 | } |
| 22 | |
| 23 | const int& bad4() |
| 24 | { |
| 25 | return int(); |
| 26 | } |