| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -fblocks -verify %s |
| 2 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -fblocks -verify %s -analyzer-config c++-allocator-inlining=false |
| 3 |
#include "Inputs/system-header-simulator-cxx.h" |
| 4 |
|
| 5 |
// expected-no-diagnostics |
| 6 |
|
| 7 |
|
| 8 |
void *allocator(std::size_t size); |
| 9 |
|
| 10 |
void *operator new[](std::size_t size) throw() { return allocator(size); } |
| 11 |
void *operator new(std::size_t size) throw() { return allocator(size); } |
| 12 |
void *operator new(std::size_t size, const std::nothrow_t ¬hrow) throw() { return allocator(size); } |
| 13 |
void *operator new(std::size_t, double d); |
| 14 |
|
| 15 |
class C { |
| 16 |
public: |
| 17 |
void *operator new(std::size_t); |
| 18 |
}; |
| 19 |
|
| 20 |
void testNewMethod() { |
| 21 |
void *p1 = C::operator new(0); // no warn |
| 22 |
|
| 23 |
C *p2 = new C; // no-warning |
| 24 |
|
| 25 |
C *c3 = ::new C; // no-warning |
| 26 |
} |
| 27 |
|
| 28 |
void testOpNewArray() { |
| 29 |
void *p = operator new[](0); // call is inlined, no warn |
| 30 |
} |
| 31 |
|
| 32 |
void testNewExprArray() { |
| 33 |
int *p = new int[0]; // no-warning |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
//----- Custom non-placement operators |
| 38 |
void testOpNew() { |
| 39 |
void *p = operator new(0); // call is inlined, no warn |
| 40 |
} |
| 41 |
|
| 42 |
void testNewExpr() { |
| 43 |
int *p = new int; // no-warning |
| 44 |
} |
| 45 |
|
| 46 |
//----- Custom NoThrow placement operators |
| 47 |
void testOpNewNoThrow() { |
| 48 |
void *p = operator new(0, std::nothrow); // call is inlined, no warn |
| 49 |
} |
| 50 |
|
| 51 |
void testNewExprNoThrow() { |
| 52 |
int *p = new(std::nothrow) int; // no-warning |
| 53 |
} |
| 54 |
|
| 55 |
//----- Custom placement operators |
| 56 |
void testOpNewPlacement() { |
| 57 |
void *p = operator new(0, 0.1); // no warn |
| 58 |
} |
| 59 |
|
| 60 |
void testNewExprPlacement() { |
| 61 |
int *p = new(0.1) int; // no warn |
| 62 |
} |