[Lldb-commits] [lldb] r370315 - [lldb][NFC] Also test operator new/new[]/delete/delete[]/comma/addr-of

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 29 02:39:33 PDT 2019


Author: teemperor
Date: Thu Aug 29 02:39:33 2019
New Revision: 370315

URL: http://llvm.org/viewvc/llvm-project?rev=370315&view=rev
Log:
[lldb][NFC] Also test operator new/new[]/delete/delete[]/comma/addr-of

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operators/main.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operators/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operators/main.cpp?rev=370315&r1=370314&r2=370315&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operators/main.cpp (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/operators/main.cpp Thu Aug 29 02:39:33 2019
@@ -1,8 +1,13 @@
 #include <cstdlib>
 
+int side_effect = 0;
+
 struct B { int dummy = 2324; };
 struct C {
   void *operator new(size_t size) { C* r = ::new C; r->custom_new = true; return r; }
+  void *operator new[](size_t size) { C* r = static_cast<C*>(std::malloc(size)); r->custom_new = true; return r; }
+  void operator delete(void *p) { std::free(p); side_effect = 1; }
+  void operator delete[](void *p) { std::free(p); side_effect = 2; }
 
   bool custom_new = false;
   B b;
@@ -48,6 +53,9 @@ struct C {
   int operator>=(int) { return 87; }
   int operator>>=(int) { return 88; }
 
+  int operator,(int) { return 2012; }
+  int operator&() { return 2013; }
+
   int operator()(int) { return 91; }
   int operator[](int) { return 92; }
 
@@ -104,6 +112,9 @@ int main(int argc, char **argv) {
   result += c>=2;
   result += c>>=2;
 
+  result += (c , 2);
+  result += &c;
+
   result += c(1);
   result += c[1];
 
@@ -113,6 +124,7 @@ int main(int argc, char **argv) {
   result += c.operatornew();
 
   C *c2 = new C();
+  C *c3 = new C[3];
 
   //% self.expect("expr c->dummy", endstr=" 2324\n")
   //% self.expect("expr c->*2", endstr=" 2\n")
@@ -151,6 +163,8 @@ int main(int argc, char **argv) {
   //% self.expect("expr c>>1", endstr=" 86\n")
   //% self.expect("expr c>=1", endstr=" 87\n")
   //% self.expect("expr c>>=1", endstr=" 88\n")
+  //% self.expect("expr c,1", endstr=" 2012\n")
+  //% self.expect("expr &c", endstr=" 2013\n")
   //% self.expect("expr c(1)", endstr=" 91\n")
   //% self.expect("expr c[1]", endstr=" 92\n")
   //% self.expect("expr static_cast<int>(c)", endstr=" 11\n")
@@ -158,6 +172,10 @@ int main(int argc, char **argv) {
   //% self.expect("expr c.operatorint()", endstr=" 13\n")
   //% self.expect("expr c.operatornew()", endstr=" 14\n")
   //% self.expect("expr (new C)->custom_new", endstr=" true\n")
+  //% self.expect("expr (new struct C[1])->custom_new", endstr=" true\n")
+  //% self.expect("expr delete c2; side_effect", endstr=" = 1\n")
+  //% self.expect("expr delete[] c3; side_effect", endstr=" = 2\n")
   delete c2;
+  delete[] c3;
   return 0;
 }




More information about the lldb-commits mailing list