2 // RUN: %clang_cc1 -fsyntax-only -include %S/delete-mismatch.h -fdiagnostics-parseable-fixits -std=c++11 %s 2>&1 | FileCheck %s
5 // RUN: %clang_cc1 -x c++-header -std=c++11 -emit-pch -o %t %S/delete-mismatch.h
6 // RUN: %clang_cc1 -std=c++11 -include-pch %t -DWITH_PCH -fsyntax-only -verify %s -ast-dump
8 void f(int a
[10][20]) {
9 delete a
; // expected-warning {{'delete' applied to a pointer-to-array type}}
10 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:9}:"[]"
12 namespace MemberCheck
{
14 int *a
= new int[5]; // expected-note4 {{allocated with 'new[]' here}}
21 delete a
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
22 delete b
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
23 delete[] c
; // expected-warning {{'delete[]' applied to a pointer that was allocated with 'new'; did you mean 'delete'?}}
30 delete a
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
31 delete b
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
35 : b(new int[1]), c(new int) {} // expected-note3 {{allocated with 'new[]' here}}
36 // expected-note@-1 {{allocated with 'new' here}}
39 : b(new int[i
]), c(new int) {} // expected-note3 {{allocated with 'new[]' here}}
40 // expected-note@-1 {{allocated with 'new' here}}
44 delete a
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
47 int *S::d
= new int[42]; // expected-note {{allocated with 'new[]' here}}
49 int *a
= new int[1]; // expected-note {{allocated with 'new[]' here}}
50 delete a
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
51 delete s
->a
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
52 delete s
->b
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
55 delete S::d
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
58 // At least one constructor initializes field with matching form of 'new'.
59 struct MatchingNewIsOK
{
62 MatchingNewIsOK() : p
{new int}, is_array_(false) {}
63 explicit MatchingNewIsOK(unsigned c
) : p
{new int[c
]}, is_array_(true) {}
72 // At least one constructor's body is missing; no proof of mismatch.
73 struct CantProve_MissingCtorDefinition
{
75 CantProve_MissingCtorDefinition();
76 CantProve_MissingCtorDefinition(int);
77 ~CantProve_MissingCtorDefinition();
80 CantProve_MissingCtorDefinition::CantProve_MissingCtorDefinition()
84 CantProve_MissingCtorDefinition::~CantProve_MissingCtorDefinition()
90 struct derived
: base
{};
92 base
*p
, *p2
= nullptr, *p3
{nullptr}, *p4
;
93 InitList(unsigned c
) : p(new derived
[c
]), p4(nullptr) {} // expected-note {{allocated with 'new[]' here}}
94 InitList(unsigned c
, unsigned) : p
{new derived
[c
]}, p4
{nullptr} {} // expected-note {{allocated with 'new[]' here}}
96 delete p
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
105 namespace NonMemberCheck
{
106 #define DELETE_ARRAY(x) delete[] (x)
107 #define DELETE(x) delete (x)
109 int *a
= new int(5); // expected-note2 {{allocated with 'new' here}}
110 delete[] a
; // expected-warning {{'delete[]' applied to a pointer that was allocated with 'new'; did you mean 'delete'?}}
113 int *c
{new int}; // expected-note {{allocated with 'new' here}}
114 int *d
{new int[1]}; // expected-note2 {{allocated with 'new[]' here}}
115 delete [ ] c
; // expected-warning {{'delete[]' applied to a pointer that was allocated with 'new'; did you mean 'delete'?}}
116 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:17}:""
117 delete d
; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
118 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:9}:"[]"
119 DELETE_ARRAY(a
); // expected-warning {{'delete[]' applied to a pointer that was allocated with 'new'; did you mean 'delete'?}}
120 DELETE(d
); // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
124 namespace MissingInitializer
{
128 const T
*p1
= nullptr;
129 const T
*p2
= new T
[3];
133 void null_init(Base
<double>::S s
) {
141 : a(new int[1]) // expected-note{{allocated with 'new[]' here}}
143 pch_test::X::X(int i
)
144 : a(new int[i
]) // expected-note{{allocated with 'new[]' here}}