libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

pointer_deleter_throw.pass.cpp (1157B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: libcpp-no-exceptions
     11 // UNSUPPORTED: sanitizer-new-delete
     12 
     13 // <memory>
     14 
     15 // shared_ptr
     16 
     17 // template<class Y, class D> shared_ptr(Y* p, D d);
     18 
     19 #include <memory>
     20 #include <cassert>
     21 #include <new>
     22 #include <cstdlib>
     23 
     24 #include "count_new.hpp"
     25 #include "deleter_types.h"
     26 
     27 struct A
     28 {
     29     static int count;
     30 
     31     A() {++count;}
     32     A(const A&) {++count;}
     33     ~A() {--count;}
     34 };
     35 
     36 int A::count = 0;
     37 
     38 int main()
     39 {
     40     A* ptr = new A;
     41     globalMemCounter.throw_after = 0;
     42     try
     43     {
     44         std::shared_ptr<A> p(ptr, test_deleter<A>(3));
     45         assert(false);
     46     }
     47     catch (std::bad_alloc&)
     48     {
     49         assert(A::count == 0);
     50         assert(test_deleter<A>::count == 0);
     51         assert(test_deleter<A>::dealloc_count == 1);
     52     }
     53     assert(globalMemCounter.checkOutstandingNewEq(0));
     54 }