1 // { dg-additional-options "-O0 -fno-analyzer-suppress-followups -fexceptions" }
10 void test_spurious_null_warning_throwing ()
12 int *x = new int; /* { dg-bogus "dereference of possibly-NULL" } */
13 int *y = new int (); /* { dg-bogus "dereference of possibly-NULL" "non-throwing" } */
14 int *arr = new int[3]; /* { dg-bogus "dereference of possibly-NULL" } */
15 A *a = new A (); /* { dg-bogus "dereference of possibly-NULL" "throwing new cannot be null" } */
18 z = *x + 4; /* { dg-bogus "dereference of possibly-NULL 'x'" } */
19 /* { dg-warning "use of uninitialized value '\\*x'" "" { target *-*-* } .-1 } */
20 z = arr[0] + 4; /* { dg-bogus "dereference of possibly-NULL" } */
21 /* { dg-warning "use of uninitialized value '\\*arr'" "" { target *-*-* } .-1 } */
29 void test_default_initialization ()
32 int *x = ::new int (); /* { dg-bogus "dereference of possibly-NULL 'operator new" } */
34 int b = *x + 3; /* { dg-bogus "dereference of possibly-NULL" } */
35 /* { dg-bogus "use of uninitialized ‘*x’" "" { target *-*-* } .-1 } */
36 int a = *y + 2; /* { dg-bogus "dereference of possibly-NULL 'y'" } */
37 /* { dg-warning "use of uninitialized value '\\*y'" "no default init" { target *-*-* } .-1 } */
43 /* From clang core.uninitialized.NewArraySize
44 new[] should not be called with an undefined size argument */
46 void test_garbage_new_array ()
49 int *arr = ::new int[n]; /* { dg-warning "use of uninitialized value 'n'" } */
51 ::delete[] arr; /* no warnings emitted here either */
54 void test_nonthrowing ()
56 int* x = new(std::nothrow) int;
57 int* y = new(std::nothrow) int();
58 int* arr = new(std::nothrow) int[10];
60 int z = *y + 2; /* { dg-warning "dereference of NULL 'y'" } */
61 /* { dg-bogus "use of uninitialized value '\\*y'" "" { target *-*-* } .-1 } */
62 z = *x + 4; /* { dg-warning "dereference of possibly-NULL 'x'" } */
63 /* { dg-warning "use of uninitialized value '\\*x'" "" { target *-*-* } .-1 } */
64 z = arr[0] + 4; /* { dg-warning "dereference of possibly-NULL 'arr'" } */
65 /* { dg-warning "use of uninitialized value '\\*arr'" "" { target *-*-* } .-1 } */