| 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 |
// <memory> |
| 10 |
|
| 11 |
// shared_ptr |
| 12 |
|
| 13 |
// explicit operator bool() const; |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
#include <cassert> |
| 17 |
#include <type_traits> |
| 18 |
|
| 19 |
#include "test_macros.h" |
| 20 |
|
| 21 |
struct A { |
| 22 |
int a; |
| 23 |
virtual ~A() {} |
| 24 |
}; |
| 25 |
struct B : A {}; |
| 26 |
|
| 27 |
int main(int, char**) |
| 28 |
{ |
| 29 |
static_assert(std::is_constructible<bool, std::shared_ptr<A> >::value, ""); |
| 30 |
static_assert(!std::is_convertible<std::shared_ptr<A>, bool>::value, ""); |
| 31 |
|
| 32 |
{ |
| 33 |
const std::shared_ptr<int> p(new int(32)); |
| 34 |
assert(p); |
| 35 |
} |
| 36 |
{ |
| 37 |
const std::shared_ptr<int> p; |
| 38 |
assert(!p); |
| 39 |
} |
| 40 |
#if !defined(TEST_HAS_NO_RTTI) |
| 41 |
{ |
| 42 |
std::shared_ptr<A> basePtr = std::make_shared<B>(); |
| 43 |
std::shared_ptr<B> sp = std::dynamic_pointer_cast<B>(basePtr); |
| 44 |
assert(sp); |
| 45 |
} |
| 46 |
#endif |
| 47 |
|
| 48 |
return 0; |
| 49 |
} |