| 1 |
/* { dg-do compile } |
| 2 |
{ dg-options "-O1 -Wall -Wno-class-memaccess -Wno-dangling-reference" } */ |
| 3 |
|
| 4 |
struct A { A (); }; |
| 5 |
|
| 6 |
const A& return_arg (const A &a) |
| 7 |
{ |
| 8 |
return a; |
| 9 |
} |
| 10 |
|
| 11 |
void sink (const void*); |
| 12 |
|
| 13 |
void nowarn_ref (int i) |
| 14 |
{ |
| 15 |
const A &a = return_arg (A ()); // { dg-note "unnamed temporary" } |
| 16 |
sink (&a); // { dg-warning "-Wdangling-pointer" } |
| 17 |
} |
| 18 |
|
| 19 |
void warn_dangling_ref (int i) |
| 20 |
{ |
| 21 |
const A &a = return_arg (A ()); // { dg-note "unnamed temporary" } |
| 22 |
sink (&a); // { dg-warning "-Wdangling-pointer" } |
| 23 |
} |