| 1 |
/* Very that -Wnonnull is issued for calls to inline member functions |
| 2 |
with a null this pointer. |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-Wall" } */ |
| 5 |
|
| 6 |
#if __cplusplus < 201103L |
| 7 |
# define nullptr 0 |
| 8 |
#endif |
| 9 |
|
| 10 |
struct S |
| 11 |
{ |
| 12 |
void f () { } |
| 13 |
static void g () { } |
| 14 |
virtual void h () { } |
| 15 |
}; |
| 16 |
|
| 17 |
void f0 () |
| 18 |
{ |
| 19 |
static_cast<S*>(0)->f (); // { dg-warning "-Wnonnull" } |
| 20 |
static_cast<S*>(0)->g (); |
| 21 |
static_cast<S*>(0)->h (); // { dg-warning "-Wnonnull" } |
| 22 |
} |
| 23 |
|
| 24 |
void f1 () |
| 25 |
{ |
| 26 |
static_cast<S*>(nullptr)->f (); // { dg-warning "-Wnonnull" } |
| 27 |
static_cast<S*>(nullptr)->g (); |
| 28 |
static_cast<S*>(nullptr)->h (); // { dg-warning "-Wnonnull" } |
| 29 |
} |
| 30 |
|
| 31 |
void f2 () |
| 32 |
{ |
| 33 |
S* const p = 0; |
| 34 |
|
| 35 |
p->f (); // { dg-warning "-Wnonnull" } |
| 36 |
p->g (); |
| 37 |
p->h (); // { dg-warning "-Wnonnull" } |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
#pragma GCC optimize "1" |
| 42 |
|
| 43 |
void f3 () |
| 44 |
{ |
| 45 |
S *p = 0; |
| 46 |
|
| 47 |
p->f (); // { dg-warning "-Wnonnull" } |
| 48 |
p->g (); |
| 49 |
p->h (); // { dg-warning "-Wnonnull" } |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
#pragma GCC optimize "2" |
| 54 |
|
| 55 |
void f4 (S *p) |
| 56 |
{ |
| 57 |
if (p) |
| 58 |
return; |
| 59 |
|
| 60 |
p->f (); // { dg-warning "-Wnonnull" } |
| 61 |
p->g (); |
| 62 |
p->h (); // { dg-warning "-Wnonnull" } |
| 63 |
} |