| 1 |
#include <new> |
| 2 |
#include <cstddef> |
| 3 |
|
| 4 |
struct foo |
| 5 |
{ |
| 6 |
foo (int i) : m_i (i) {} // { dg-message "argument 'this' of 'foo::foo\\(int\\)' must be non-null" "note" } |
| 7 |
|
| 8 |
int get () const { return m_i; } // { dg-message "argument 'this' of '\[^\n\]*' must be non-null" "note" } |
| 9 |
|
| 10 |
int meth_1 (int, void *ptr) __attribute__((nonnull)); // { dg-message "argument 2 of '\[^\n\]*' must be non-null" "note" } |
| 11 |
int meth_2 (int, void *ptr) __attribute__((nonnull(3))); // { dg-message "argument 2 of '\[^\n\]*' must be non-null" "note" } |
| 12 |
|
| 13 |
int m_i; |
| 14 |
}; |
| 15 |
|
| 16 |
void test_1 (void) |
| 17 |
{ |
| 18 |
foo *p = new(NULL) foo (42); // { dg-warning "non-null expected" "warning" } |
| 19 |
// { dg-message "argument 'this'( \\(\[^\n\]*\\))? NULL where non-null expected" "final event" { target *-*-* } .-1 } |
| 20 |
} |
| 21 |
|
| 22 |
int test_2 (void) |
| 23 |
{ |
| 24 |
foo *p = NULL; |
| 25 |
return p->get (); // { dg-warning "non-null expected" "warning" } |
| 26 |
// { dg-message "argument 'this' \\('p'\\) NULL where non-null expected" "final event" { target *-*-* } .-1 } |
| 27 |
} |
| 28 |
|
| 29 |
int test_meth_1 (foo *f) |
| 30 |
{ |
| 31 |
return f->meth_1 (42, NULL); // { dg-warning "non-null expected" "warning" } |
| 32 |
// { dg-message "argument 2 NULL where non-null expected" "final event" { target *-*-* } .-1 } |
| 33 |
} |
| 34 |
|
| 35 |
int test_meth_2 (foo *f) |
| 36 |
{ |
| 37 |
return f->meth_2 (42, NULL); // { dg-warning "non-null expected" "warning" } |
| 38 |
// { dg-message "argument 2 NULL where non-null expected" "final event" { target *-*-* } .-1 } |
| 39 |
} |