63 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -fblocks -verify %s2// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -fblocks -verify %s -analyzer-config c++-allocator-inlining=false3#include "Inputs/system-header-simulator-cxx.h"4 5// expected-no-diagnostics6 7 8void *allocator(std::size_t size);9 10void *operator new[](std::size_t size) throw() { return allocator(size); }11void *operator new(std::size_t size) throw() { return allocator(size); }12void *operator new(std::size_t size, const std::nothrow_t ¬hrow) throw() { return allocator(size); }13void *operator new(std::size_t, double d);14 15class C {16public:17 void *operator new(std::size_t); 18};19 20void testNewMethod() {21 void *p1 = C::operator new(0); // no warn22 23 C *p2 = new C; // no-warning24 25 C *c3 = ::new C; // no-warning26}27 28void testOpNewArray() {29 void *p = operator new[](0); // call is inlined, no warn30}31 32void testNewExprArray() {33 int *p = new int[0]; // no-warning34}35 36 37//----- Custom non-placement operators38void testOpNew() {39 void *p = operator new(0); // call is inlined, no warn40}41 42void testNewExpr() {43 int *p = new int; // no-warning44}45 46//----- Custom NoThrow placement operators47void testOpNewNoThrow() {48 void *p = operator new(0, std::nothrow); // call is inlined, no warn49}50 51void testNewExprNoThrow() {52 int *p = new(std::nothrow) int; // no-warning53}54 55//----- Custom placement operators56void testOpNewPlacement() {57 void *p = operator new(0, 0.1); // no warn58}59 60void testNewExprPlacement() {61 int *p = new(0.1) int; // no warn62}63