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() noexcept; 18 19 #include <experimental/memory> 20 #include <type_traits> 21 #include <cassert> 22 23 template <class T> test_default_ctor()24constexpr void test_default_ctor() { 25 using Ptr = std::experimental::observer_ptr<T>; 26 Ptr ptr; 27 assert(ptr.get() == nullptr); 28 static_assert(std::is_nothrow_default_constructible<Ptr>::value); 29 } 30 31 struct Foo; 32 struct Bar { BarBar33 Bar(int) {} 34 }; 35 test()36constexpr bool test() { 37 test_default_ctor<Foo>(); 38 test_default_ctor<Bar>(); 39 test_default_ctor<int>(); 40 test_default_ctor<void>(); 41 42 return true; 43 } 44 main(int,char **)45int main(int, char**) { 46 test(); 47 static_assert(test()); 48 49 return 0; 50 } 51