1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template<class Y> explicit shared_ptr(Y* p);
15 #include <type_traits>
17 #include "test_macros.h"
24 A(const A
&) {++count
;}
30 struct derived
: A
{};
32 // https://llvm.org/PR60258
33 // Invalid constructor SFINAE for std::shared_ptr's array ctors
34 static_assert( std::is_constructible
<std::shared_ptr
<int>, int*>::value
, "");
35 static_assert( std::is_constructible
<std::shared_ptr
<A
>, derived
*>::value
, "");
36 static_assert(!std::is_constructible
<std::shared_ptr
<A
>, int*>::value
, "");
38 #if TEST_STD_VER >= 17
39 static_assert( std::is_constructible
<std::shared_ptr
<int[]>, int*>::value
, "");
40 static_assert(!std::is_constructible
<std::shared_ptr
<int[]>, int(*)[]>::value
, "");
41 static_assert( std::is_constructible
<std::shared_ptr
<int[5]>, int*>::value
, "");
42 static_assert(!std::is_constructible
<std::shared_ptr
<int[5]>, int(*)[5]>::value
, "");
46 static_assert(std::is_constructible
<std::shared_ptr
<int>, int*>::value
, "");
47 static_assert(!std::is_convertible
<int*, std::shared_ptr
<int> >::value
, "");
52 assert(A::count
== 0);
54 std::shared_ptr
<A
> p(ptr
);
55 assert(A::count
== 1);
56 assert(p
.use_count() == 1);
57 assert(p
.get() == ptr
);
61 assert(A::count
== 0);
63 std::shared_ptr
<A
const> p(ptr
);
64 assert(A::count
== 1);
65 assert(p
.use_count() == 1);
66 assert(p
.get() == ptr
);
70 assert(A::count
== 0);
72 std::shared_ptr
<void> p(ptr
);
73 assert(A::count
== 1);
74 assert(p
.use_count() == 1);
75 assert(p
.get() == ptr
);
80 assert(A::count
== 0);
81 std::shared_ptr
<A
[8]> pA(new A
[8]);
82 assert(pA
.use_count() == 1);
83 assert(A::count
== 8);
87 assert(A::count
== 0);
88 std::shared_ptr
<A
[]> pA(new A
[8]);
89 assert(pA
.use_count() == 1);
90 assert(A::count
== 8);
94 assert(A::count
== 0);
95 std::shared_ptr
<const A
[]> pA(new A
[8]);
96 assert(pA
.use_count() == 1);
97 assert(A::count
== 8);
101 assert(A::count
== 0);
102 std::shared_ptr
<A
> pA(new derived
);
103 assert(pA
.use_count() == 1);
104 assert(A::count
== 1);