1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: no-exceptions
10// UNSUPPORTED: sanitizer-new-delete
11
12// <memory>
13
14// shared_ptr
15
16// template<class D> shared_ptr(nullptr_t, D d);
17
18#include <memory>
19#include <cassert>
20#include <new>
21#include <cstdlib>
22
23#include "test_macros.h"
24#include "count_new.h"
25
26#include "deleter_types.h"
27
28struct A
29{
30 static int count;
31
32 A() {++count;}
33 A(const A&) {++count;}
34 ~A() {--count;}
35};
36
37int A::count = 0;
38
39
40int main(int, char**)
41{
42 globalMemCounter.throw_after = 0;
43 try
44 {
45 std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
46 assert(false);
47 }
48 catch (std::bad_alloc&)
49 {
50 assert(A::count == 0);
51 assert(test_deleter<A>::count == 0);
52 assert(test_deleter<A>::dealloc_count == 1);
53 }
54
55 return 0;
56}
57

source code of libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp