Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / memory / util.smartptr / util.smartptr.shared / util.smartptr.shared.obs / op_bool.pass.cpp
blobd8c067c7be8e7abd38388fe2b3de6abfe9619c67
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 //===----------------------------------------------------------------------===//
9 // <memory>
11 // shared_ptr
13 // explicit operator bool() const;
15 #include <memory>
16 #include <cassert>
17 #include <type_traits>
19 #include "test_macros.h"
21 struct A {
22 int a;
23 virtual ~A(){};
25 struct B : A {};
27 int main(int, char**)
29 static_assert(std::is_constructible<bool, std::shared_ptr<A> >::value, "");
30 static_assert(!std::is_convertible<std::shared_ptr<A>, bool>::value, "");
33 const std::shared_ptr<int> p(new int(32));
34 assert(p);
37 const std::shared_ptr<int> p;
38 assert(!p);
40 #if !defined(TEST_HAS_NO_RTTI)
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);
46 #endif
48 return 0;