diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
| commit | 809500fc2c13c8173a16b052304d983864e4a1e1 (patch) | |
| tree | 4fc2f184c499d106f29a386c452b49e5197bf63d /test/Analysis/NewDelete-custom.cpp | |
| parent | be7c9ec198dcdb5bf73a35bfbb00b3333cb87909 (diff) | |
Vendor import of clang trunk r178860:vendor/clang/clang-trunk-r178860
Notes
svn path=/vendor/clang/dist/; revision=249261
svn path=/vendor/clang/clang-trunk-r178860/; revision=249262; tag=vendor/clang/clang-trunk-r178860
Diffstat (limited to 'test/Analysis/NewDelete-custom.cpp')
| -rw-r--r-- | test/Analysis/NewDelete-custom.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/Analysis/NewDelete-custom.cpp b/test/Analysis/NewDelete-custom.cpp new file mode 100644 index 000000000000..7d7796bccb6e --- /dev/null +++ b/test/Analysis/NewDelete-custom.cpp @@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.cplusplus.NewDelete,unix.Malloc -analyzer-store region -std=c++11 -fblocks -verify %s +#include "Inputs/system-header-simulator-cxx.h" + +void *allocator(std::size_t size); + +void *operator new[](std::size_t size) throw() { return allocator(size); } +void *operator new(std::size_t size) throw() { return allocator(size); } +void *operator new(std::size_t size, std::nothrow_t& nothrow) throw() { return allocator(size); } +void *operator new(std::size_t, double d); + +class C { +public: + void *operator new(std::size_t); +}; + +void testNewMethod() { + void *p1 = C::operator new(0); // no warn + + C *p2 = new C; // no warn + + C *c3 = ::new C; +} // expected-warning{{Memory is never released; potential leak}} + +void testOpNewArray() { + void *p = operator new[](0); // call is inlined, no warn +} + +void testNewExprArray() { + int *p = new int[0]; +} // expected-warning{{Memory is never released; potential leak}} + +//----- Custom non-placement operators +void testOpNew() { + void *p = operator new(0); // call is inlined, no warn +} + +void testNewExpr() { + int *p = new int; +} // expected-warning{{Memory is never released; potential leak}} + +//----- Custom NoThrow placement operators +void testOpNewNoThrow() { + void *p = operator new(0, std::nothrow); +} // expected-warning{{Memory is never released; potential leak}} + +void testNewExprNoThrow() { + int *p = new(std::nothrow) int; +} // expected-warning{{Memory is never released; potential leak}} + +//----- Custom placement operators +void testOpNewPlacement() { + void *p = operator new(0, 0.1); // no warn +} + +void testNewExprPlacement() { + int *p = new(0.1) int; // no warn +} |
