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
24template <class T>
25constexpr 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
32struct Foo;
33struct Bar {
34 Bar(int) {}
35};
36
37constexpr 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
46int main(int, char**) {
47 test();
48 static_assert(test());
49
50 return 0;
51}
52

source code of libcxx/test/std/experimental/memory/memory.observer.ptr/ctor.nullptr.pass.cpp