Clang Project

clang_source_code/test/Analysis/NewDelete-custom.cpp
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
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 &nothrow) 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 warn
22
23  C *p2 = new C; // no-warning
24
25  C *c3 = ::new C; // no-warning
26}
27
28void testOpNewArray() {
29  void *p = operator new[](0); // call is inlined, no warn
30}
31
32void testNewExprArray() {
33  int *p = new int[0]; // no-warning
34}
35
36
37//----- Custom non-placement operators
38void testOpNew() {
39  void *p = operator new(0); // call is inlined, no warn
40}
41
42void testNewExpr() {
43  int *p = new int; // no-warning
44}
45
46//----- Custom NoThrow placement operators
47void testOpNewNoThrow() {
48  void *p = operator new(0, std::nothrow); // call is inlined, no warn
49}
50
51void testNewExprNoThrow() {
52  int *p = new(std::nothrow) int; // no-warning
53}
54
55//----- Custom placement operators
56void testOpNewPlacement() {
57  void *p = operator new(0, 0.1); // no warn
58}
59
60void testNewExprPlacement() {
61  int *p = new(0.1) int; // no warn
62}
63