//===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// // // unique_ptr // pointer unique_ptr::get() const noexcept; // pointer unique_ptr::get() const noexcept; #include #include #include #include "test_macros.h" template TEST_CONSTEXPR_CXX23 void test_basic() { // non-const element type { // non-const access { T* x = new T; std::unique_ptr ptr(x); ASSERT_SAME_TYPE(decltype(ptr.get()), T*); ASSERT_NOEXCEPT(ptr.get()); assert(ptr.get() == x); } // const access { T* x = new T; std::unique_ptr const ptr(x); ASSERT_SAME_TYPE(decltype(ptr.get()), T*); ASSERT_NOEXCEPT(ptr.get()); assert(ptr.get() == x); } } // const element type { // non-const access { T* x = new T; std::unique_ptr ptr(x); ASSERT_SAME_TYPE(decltype(ptr.get()), T const*); assert(ptr.get() == x); } // const access { T* x = new T; std::unique_ptr const ptr(x); ASSERT_SAME_TYPE(decltype(ptr.get()), T const*); assert(ptr.get() == x); } } // Same thing but for unique_ptr // non-const element type { // non-const access { T* x = new T[3]; std::unique_ptr ptr(x); ASSERT_SAME_TYPE(decltype(ptr.get()), T*); ASSERT_NOEXCEPT(ptr.get()); assert(ptr.get() == x); } // const access { T* x = new T[3]; std::unique_ptr const ptr(x); ASSERT_SAME_TYPE(decltype(ptr.get()), T*); ASSERT_NOEXCEPT(ptr.get()); assert(ptr.get() == x); } } // const element type { // non-const access { T* x = new T[3]; std::unique_ptr ptr(x); ASSERT_SAME_TYPE(decltype(ptr.get()), T const*); assert(ptr.get() == x); } // const access { T* x = new T[3]; std::unique_ptr const ptr(x); ASSERT_SAME_TYPE(decltype(ptr.get()), T const*); assert(ptr.get() == x); } } } template struct WithSize { char padding[Size]; }; TEST_CONSTEXPR_CXX23 bool test() { test_basic(); test_basic(); test_basic >(); test_basic >(); test_basic >(); test_basic >(); test_basic >(); test_basic >(); test_basic >(); return true; } int main(int, char**) { test(); #if TEST_STD_VER >= 23 static_assert(test()); #endif return 0; }