make_shared.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <memory>
11
12// shared_ptr
13
14// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
15
16#include <memory>
17#include <new>
18#include <cstdlib>
19#include <cassert>
20
21int new_count = 0;
22
23void* operator new(std::size_t s) throw(std::bad_alloc)
24{
25    ++new_count;
26    return std::malloc(s);
27}
28
29void  operator delete(void* p) throw()
30{
31    std::free(p);
32}
33
34struct A
35{
36    static int count;
37
38    A(int i, char c) : int_(i), char_(c) {++count;}
39    A(const A& a)
40        : int_(a.int_), char_(a.char_)
41        {++count;}
42    ~A() {--count;}
43
44    int get_int() const {return int_;}
45    char get_char() const {return char_;}
46private:
47    int int_;
48    char char_;
49};
50
51int A::count = 0;
52
53int main()
54{
55    int nc = new_count;
56    {
57    int i = 67;
58    char c = 'e';
59    std::shared_ptr<A> p = std::make_shared<A>(i, c);
60    assert(new_count == nc+1);
61    assert(A::count == 1);
62    assert(p->get_int() == 67);
63    assert(p->get_char() == 'e');
64    }
65    assert(A::count == 0);
66}
67