// -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14 // REQUIRES: c++experimental // // observer_ptr // // template // constexpr observer_ptr(observer_ptr other) noexcept; #include #include #include #include "test_macros.h" template constexpr void test_converting_ctor() { using ToPtr = std::experimental::observer_ptr; using FromPtr = std::experimental::observer_ptr; From obj; FromPtr from(&obj); ToPtr to = from; assert(from.get() == &obj); assert(to.get() == &obj); #if TEST_STD_VER >= 20 static_assert(std::is_nothrow_convertible::value); #endif } template constexpr void check_non_constructible() { using ToPtr = std::experimental::observer_ptr; using FromPtr = std::experimental::observer_ptr; static_assert(!std::is_constructible::value); } struct Bar {}; struct Base {}; struct Derived : Base {}; constexpr bool test() { test_converting_ctor(); test_converting_ctor(); test_converting_ctor(); check_non_constructible(); check_non_constructible(); check_non_constructible(); check_non_constructible(); check_non_constructible(); // Check const-ness check_non_constructible(); test_converting_ctor(); return true; } int main(int, char**) { test(); static_assert(test()); return 0; }