<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Modified: cfe/trunk/test/SemaCXX/delete.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_test_SemaCXX_delete.cpp-3Frev-3D237608-26r1-3D237607-26r2-3D237608-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m=BAqLvUj_b32UnKD2kUQ1rDm6RUSO4FqcRp8m1afCbzA&s=otBv80X0DSelRxNN1xAn4HI2jt4Tca5I9x-DcCO9OEg&e=" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/delete.cpp?rev=237608&r1=237607&r2=237608&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/delete.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/delete.cpp Mon May 18 14:59:11 2015<br>
@@ -1,9 +1,130 @@<br>
-// RUN: %clang_cc1 -fsyntax-only -verify %s<br>
-// RUN: cp %s %t<br>
-// RUN: %clang_cc1 -fixit -x c++ %t<br>
-// RUN: %clang_cc1 -E -o - %t | FileCheck %s<br>
+// Test without PCH<br>
+// RUN: %clang_cc1 -fsyntax-only -include %S/delete-mismatch.h -fdiagnostics-parseable-fixits -std=c++11 %s 2>&1 | FileCheck %s<br>
+<br>
+// Test with PCH<br>
+// RUN: %clang_cc1 -x c++-header -std=c++11 -emit-pch -o %t %S/delete-mismatch.h<br>
+// RUN: %clang_cc1 -std=c++11 -include-pch %t -DWITH_PCH -fsyntax-only -verify %s -ast-dump<br></blockquote><div>Why is an AST dump being performed here? </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
 void f(int a[10][20]) {<br>
-  // CHECK: delete[] a;<br>
   delete a; // expected-warning {{'delete' applied to a pointer-to-array type}}<br>
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:9}:"[]"<br>
+}<br>
+namespace MemberCheck {<br>
+struct S {<br>
+  int *a = new int[5]; // expected-note4 {{allocated with 'new[]' here}}<br>
+  int *b;<br>
+  int *c;<br>
+  static int *d;<br>
+  S();<br>
+  S(int);<br>
+  ~S() {<br>
+    delete a; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+    delete b;   // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+    delete[] c; // expected-warning {{'delete[]' applied to a pointer that was allocated with 'new'; did you mean 'delete'?}}<br>
+  }<br>
+  void f();<br>
+};<br>
+<br>
+void S::f()<br>
+{<br>
+  delete a; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+  delete b; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+}<br>
+<br>
+S::S()<br>
+: b(new int[1]), c(new int) {} // expected-note3 {{allocated with 'new[]' here}}<br>
+// expected-note@-1 {{allocated with 'new' here}}<br>
+<br>
+S::S(int i)<br>
+: b(new int[i]), c(new int) {} // expected-note3 {{allocated with 'new[]' here}}<br>
+// expected-note@-1 {{allocated with 'new' here}}<br>
+<br>
+struct S2 : S {<br>
+  ~S2() {<br>
+    delete a; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+  }<br>
+};<br>
+int *S::d = new int[42]; // expected-note {{allocated with 'new[]' here}}<br>
+void f(S *s) {<br>
+  int *a = new int[1]; // expected-note {{allocated with 'new[]' here}}<br>
+  delete a; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+  delete s->a; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+  delete s->b; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+  delete s->c;<br>
+  delete s->d;<br>
+  delete S::d; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+}<br>
+<br>
+// At least one constructor initializes field with matching form of 'new'.<br>
+struct MatchingNewIsOK {<br>
+  int *p;<br>
+  bool is_array_;<br>
+  MatchingNewIsOK() : p{new int}, is_array_(false) {}<br>
+  explicit MatchingNewIsOK(unsigned c) : p{new int[c]}, is_array_(true) {}<br>
+  ~MatchingNewIsOK() {<br>
+    if (is_array_)<br>
+      delete[] p;<br>
+    else<br>
+      delete p;<br>
+  }<br>
+};<br>
+<br>
+// At least one constructor's body is missing; no proof of mismatch.<br>
+struct CantProve_MissingCtorDefinition {<br>
+  int *p;<br>
+  CantProve_MissingCtorDefinition();<br>
+  CantProve_MissingCtorDefinition(int);<br>
+  ~CantProve_MissingCtorDefinition();<br>
+};<br>
+<br>
+CantProve_MissingCtorDefinition::CantProve_MissingCtorDefinition()<br>
+  : p(new int)<br>
+{ }<br>
+<br>
+CantProve_MissingCtorDefinition::~CantProve_MissingCtorDefinition()<br>
+{<br>
+  delete[] p;<br>
+}<br>
+<br>
+struct base {};<br>
+struct derived : base {};<br>
+struct InitList {<br>
+  base *p, *p2 = nullptr, *p3{nullptr}, *p4;<br>
+  InitList(unsigned c) : p(new derived[c]), p4(nullptr) {}  // expected-note {{allocated with 'new[]' here}}<br>
+  InitList(unsigned c, unsigned) : p{new derived[c]}, p4{nullptr} {} // expected-note {{allocated with 'new[]' here}}<br>
+  ~InitList() {<br>
+    delete p; // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+    delete [] p;<br>
+    delete p2;<br>
+    delete [] p3;<br>
+    delete p4;<br>
+  }<br>
+};<br>
+}<br>
+<br>
+namespace NonMemberCheck {<br>
+#define DELETE_ARRAY(x) delete[] (x)<br>
+#define DELETE(x) delete (x)<br>
+void f() {<br>
+  int *a = new int(5); // expected-note2 {{allocated with 'new' here}}<br>
+  delete[] a;          // expected-warning {{'delete[]' applied to a pointer that was allocated with 'new'; did you mean 'delete'?}}<br>
+  int *b = new int;<br>
+  delete b;<br>
+  int *c{new int};    // expected-note {{allocated with 'new' here}}<br>
+  int *d{new int[1]}; // expected-note2 {{allocated with 'new[]' here}}<br>
+  delete  [    ] c;   // expected-warning {{'delete[]' applied to a pointer that was allocated with 'new'; did you mean 'delete'?}}<br>
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:17}:""<br>
+  delete d;           // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:9}:"[]"<br>
+  DELETE_ARRAY(a);    // expected-warning {{'delete[]' applied to a pointer that was allocated with 'new'; did you mean 'delete'?}}<br>
+  DELETE(d);          // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}<br>
+}<br>
 }<br>
+#ifndef WITH_PCH<br>
+pch_test::X::X()<br>
+  : a(new int[1])  // expected-note{{allocated with 'new[]' here}}<br>
+{ }<br>
+pch_test::X::X(int i)<br>
+  : a(new int[i])  // expected-note{{allocated with 'new[]' here}}<br>
+{ }<br>
+#endif<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>