| 1 |
/* PR middle-end/104436 - spurious -Wdangling-pointer assigning local |
| 2 |
address to a class passed by value |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O1 -Wall" } */ |
| 5 |
|
| 6 |
struct S |
| 7 |
{ |
| 8 |
S (void *p): p (p) { } |
| 9 |
S (const S &s): p (s.p) { } |
| 10 |
|
| 11 |
void *p; |
| 12 |
}; |
| 13 |
|
| 14 |
|
| 15 |
void nowarn_assign_by_value (S s) |
| 16 |
{ |
| 17 |
int i; |
| 18 |
S t (&i); |
| 19 |
s = t; // { dg-bogus "-Wdangling-pointer" } |
| 20 |
} |
| 21 |
|
| 22 |
void nowarn_assign_by_value_arg (S s) |
| 23 |
{ |
| 24 |
S t (&s); |
| 25 |
s = t; // { dg-bogus "-Wdangling-pointer" } |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
void warn_assign_local_by_reference (S &s) |
| 30 |
{ |
| 31 |
int i; |
| 32 |
S t (&i); |
| 33 |
s = t; // { dg-warning "-Wdangling-pointer" } |
| 34 |
} |