Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wreturn-local-addr.C

raw
1 // { dg-do assemble }
2 // { dg-options "-Werror=return-local-addr" }
3 // { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 }
4
5 int& bad1()
6 {
7 int x = 0;
8 return x; // { dg-error "reference to local variable|cannot bind non-const lvalue reference" }
9 }
10
11 int* bad2()
12 {
13 int x = 0;
14 return &x; // { dg-error "address of local variable" }
15 }
16
17 const int& bad4()
18 {
19 return int(); // { dg-error "returning reference to temporary" }
20 }