xref: /llvm-project/libcxx/test/std/experimental/memory/memory.observer.ptr/ctor.nullptr.pass.cpp (revision 7a62bee611f1c451fa026c146b03a3a277a5a1dd)
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++03, c++11, c++14
11 // REQUIRES: c++experimental
12 
13 // <experimental/memory>
14 
15 // observer_ptr
16 //
17 // constexpr observer_ptr(nullptr_t) noexcept;
18 
19 #include <experimental/memory>
20 #include <cassert>
21 #include <cstddef>
22 #include <type_traits>
23 
24 template <class T>
test_nullptr_ctor()25 constexpr void test_nullptr_ctor() {
26   using Ptr = std::experimental::observer_ptr<T>;
27   Ptr ptr   = nullptr;
28   assert(ptr.get() == nullptr);
29   static_assert(std::is_nothrow_constructible<Ptr, std::nullptr_t>::value);
30 }
31 
32 struct Foo;
33 struct Bar {
BarBar34   Bar(int) {}
35 };
36 
test()37 constexpr bool test() {
38   test_nullptr_ctor<Foo>();
39   test_nullptr_ctor<Bar>();
40   test_nullptr_ctor<int>();
41   test_nullptr_ctor<void>();
42 
43   return true;
44 }
45 
main(int,char **)46 int main(int, char**) {
47   test();
48   static_assert(test());
49 
50   return 0;
51 }
52