diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.msvc/test.compile.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.msvc/test.compile.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.msvc/test.compile.pass.cpp +++ /dev/null @@ -1,13 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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, c++17, c++20 - -// Includes Microsoft's test that tests the entire header. - -#include "test.cpp" diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.msvc/test.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.msvc/test.cpp deleted file mode 100644 --- a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.msvc/test.cpp +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include -#include -#include - -#include "test_macros.h" - -using namespace std; - -struct Dummy { - constexpr int test() const { return 10; } -}; - -constexpr bool test() { - // [memory.syn] - { - // FIXME no make_unique_for_overwrite support - //auto p1 = make_unique(42); - //auto p2 = make_unique_for_overwrite(); - //swap(p1, p2); - //assert(p1 == p1); - //assert(p1 != p2); - - //auto p3 = make_unique(10); - //auto p4 = make_unique_for_overwrite(4); - //swap(p3, p4); - //assert(p3 == p3); - //assert(p3 != p4); - - auto p5 = unique_ptr{nullptr}; - assert(p5 == nullptr); - assert(nullptr == p5); - assert(!(p5 != nullptr)); - assert(!(nullptr != p5)); - assert(!(p5 < nullptr)); - assert(!(nullptr < p5)); - assert(p5 <= nullptr); - assert(nullptr <= p5); - assert(!(p5 > nullptr)); - assert(!(nullptr > p5)); - assert(p5 >= nullptr); - assert(nullptr >= p5); - assert((p5 <=> nullptr) == strong_ordering::equal); - assert((nullptr <=> p5) == strong_ordering::equal); - } - - // changes in [unique.ptr.dltr.dflt] and [unique.ptr.dltr.dflt1] - // will be tested via destructors and copy assign/constructors - - // [unique.ptr.single.general] - { - // constructors - auto p1 = unique_ptr{new int{}}; - auto d1 = default_delete{}; - auto p2 = unique_ptr{new int{}, d1}; - auto p3 = unique_ptr{new int{}, default_delete{}}; - auto p4 = std::move(p3); - auto p5 = unique_ptr{nullptr}; - auto p6 = unique_ptr&>{new int{}, d1}; - auto p7 = unique_ptr{std::move(p6)}; - - // assignment - p3 = std::move(p4); - auto p8 = unique_ptr&>{new int{}, d1}; - p7 = std::move(p8); - p1 = nullptr; - - // observers - assert(*p2 == 0); - auto p9 = unique_ptr{new Dummy}; - assert(p9->test() == 10); - assert(p2.get() != nullptr); - [[maybe_unused]] auto& d2 = p2.get_deleter(); - [[maybe_unused]] auto& d3 = as_const(p2).get_deleter(); - auto b1 = static_cast(p2); - assert(b1); - - // modifiers - p1.reset(); - p1.reset(new int{}); - auto manual_delete = p2.release(); - delete manual_delete; - p5.swap(p1); - } - - // [unique.ptr.runtime.general] - { - // constructors - auto p1 = unique_ptr{new int[5]}; - auto d1 = default_delete{}; - auto p2 = unique_ptr{new int[5], d1}; - auto p3 = unique_ptr{new int[5], default_delete{}}; - auto p4 = std::move(p1); - auto p5 = unique_ptr&>{new int[5], d1}; - auto p6 = unique_ptr{std::move(p5)}; - - // assignment - p1 = std::move(p4); - auto p7 = unique_ptr&>{new int[5], d1}; - p6 = std::move(p7); - p4 = nullptr; - - // observers - p1[0] = 50; - assert(p1[0] == 50); - assert(p1.get() != nullptr); - [[maybe_unused]] auto& d2 = p1.get_deleter(); - [[maybe_unused]] auto& d3 = as_const(p1).get_deleter(); - auto b1 = static_cast(p1); - assert(b1); - - // modifiers - auto manual_delete = p1.release(); - delete[] manual_delete; - p1.reset(new int[3]); - p1.reset(nullptr); - p1.reset(); - p1.swap(p4); - } - - return true; -} - -static_assert(test()); - -int main() {} // COMPILE-ONLY diff --git a/libcxx/test/std/utilities/utility/forward/forward_like.pass.cpp b/libcxx/test/std/utilities/utility/forward/forward_like.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/forward_like.pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++17, c++20 + +// test forward_like + +#include +#include +#include + +struct U {}; // class type so const-qualification is not stripped from a prvalue +using CU = const U; +using T = int; +using CT = const T; + +U u{}; +const U& cu = u; + +static_assert(std::is_same_v(U{})), U&&>); +static_assert(std::is_same_v(CU{})), CU&&>); +static_assert(std::is_same_v(u)), U&&>); +static_assert(std::is_same_v(cu)), CU&&>); +static_assert(std::is_same_v(std::move(u))), U&&>); +static_assert(std::is_same_v(std::move(cu))), CU&&>); + +static_assert(std::is_same_v(U{})), CU&&>); +static_assert(std::is_same_v(CU{})), CU&&>); +static_assert(std::is_same_v(u)), CU&&>); +static_assert(std::is_same_v(cu)), CU&&>); +static_assert(std::is_same_v(std::move(u))), CU&&>); +static_assert(std::is_same_v(std::move(cu))), CU&&>); + +static_assert(std::is_same_v(U{})), U&>); +static_assert(std::is_same_v(CU{})), CU&>); +static_assert(std::is_same_v(u)), U&>); +static_assert(std::is_same_v(cu)), CU&>); +static_assert(std::is_same_v(std::move(u))), U&>); +static_assert(std::is_same_v(std::move(cu))), CU&>); + +static_assert(std::is_same_v(U{})), CU&>); +static_assert(std::is_same_v(CU{})), CU&>); +static_assert(std::is_same_v(u)), CU&>); +static_assert(std::is_same_v(cu)), CU&>); +static_assert(std::is_same_v(std::move(u))), CU&>); +static_assert(std::is_same_v(std::move(cu))), CU&>); + +static_assert(std::is_same_v(U{})), U&&>); +static_assert(std::is_same_v(CU{})), CU&&>); +static_assert(std::is_same_v(u)), U&&>); +static_assert(std::is_same_v(cu)), CU&&>); +static_assert(std::is_same_v(std::move(u))), U&&>); +static_assert(std::is_same_v(std::move(cu))), CU&&>); + +static_assert(std::is_same_v(U{})), CU&&>); +static_assert(std::is_same_v(CU{})), CU&&>); +static_assert(std::is_same_v(u)), CU&&>); +static_assert(std::is_same_v(cu)), CU&&>); +static_assert(std::is_same_v(std::move(u))), CU&&>); +static_assert(std::is_same_v(std::move(cu))), CU&&>); + +static_assert(noexcept(std::forward_like(u))); + +static_assert(std::is_same_v(u)), U&>); +static_assert(std::is_same_v(cu)), CU&>); +static_assert(std::is_same_v(std::move(u))), U&&>); +static_assert(std::is_same_v(std::move(cu))), CU&&>); + +struct NoCtorCopyMove { + NoCtorCopyMove() = delete; + NoCtorCopyMove(const NoCtorCopyMove&) = delete; + NoCtorCopyMove(NoCtorCopyMove&&) = delete; +}; + +static_assert(std::is_same_v(std::declval())), const NoCtorCopyMove&&>); +static_assert(std::is_same_v(std::declval())), const NoCtorCopyMove&>); +static_assert(std::is_same_v(std::declval())), NoCtorCopyMove&&>); +static_assert(std::is_same_v(std::declval())), NoCtorCopyMove&>); + +static_assert(noexcept(std::forward_like(std::declval()))); + +constexpr bool test() { + { + int val = 1729; + auto&& result = std::forward_like(val); + static_assert(std::is_same_v); + assert(&result == &val); + } + { + int val = 1729; + auto&& result = std::forward_like(val); + static_assert(std::is_same_v); + assert(&result == &val); + } + { + int val = 1729; + auto&& result = std::forward_like(val); + static_assert(std::is_same_v); + assert(&result == &val); + } + { + int val = 1729; + auto&& result = std::forward_like(val); + static_assert(std::is_same_v); + assert(&result == &val); + } + return true; +} + +int main(int, char**) { + test(); + static_assert(test()); + + return 0; +} diff --git a/libcxx/test/std/utilities/utility/forward_like/forward_like.msvc/test.cpp b/libcxx/test/std/utilities/utility/forward_like/forward_like.msvc/test.cpp deleted file mode 100644 --- a/libcxx/test/std/utilities/utility/forward_like/forward_like.msvc/test.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include -#include -#include - -using namespace std; - -struct U {}; // class type so const-qualification is not stripped from a prvalue -using CU = const U; -using T = int; -using CT = const T; - -U u{}; -const U& cu = u; - -static_assert(is_same_v(U{})), U&&>); -static_assert(is_same_v(CU{})), CU&&>); -static_assert(is_same_v(u)), U&&>); -static_assert(is_same_v(cu)), CU&&>); -static_assert(is_same_v(std::move(u))), U&&>); -static_assert(is_same_v(std::move(cu))), CU&&>); - -static_assert(is_same_v(U{})), CU&&>); -static_assert(is_same_v(CU{})), CU&&>); -static_assert(is_same_v(u)), CU&&>); -static_assert(is_same_v(cu)), CU&&>); -static_assert(is_same_v(std::move(u))), CU&&>); -static_assert(is_same_v(std::move(cu))), CU&&>); - -static_assert(is_same_v(U{})), U&>); -static_assert(is_same_v(CU{})), CU&>); -static_assert(is_same_v(u)), U&>); -static_assert(is_same_v(cu)), CU&>); -static_assert(is_same_v(std::move(u))), U&>); -static_assert(is_same_v(std::move(cu))), CU&>); - -static_assert(is_same_v(U{})), CU&>); -static_assert(is_same_v(CU{})), CU&>); -static_assert(is_same_v(u)), CU&>); -static_assert(is_same_v(cu)), CU&>); -static_assert(is_same_v(std::move(u))), CU&>); -static_assert(is_same_v(std::move(cu))), CU&>); - -static_assert(is_same_v(U{})), U&&>); -static_assert(is_same_v(CU{})), CU&&>); -static_assert(is_same_v(u)), U&&>); -static_assert(is_same_v(cu)), CU&&>); -static_assert(is_same_v(std::move(u))), U&&>); -static_assert(is_same_v(std::move(cu))), CU&&>); - -static_assert(is_same_v(U{})), CU&&>); -static_assert(is_same_v(CU{})), CU&&>); -static_assert(is_same_v(u)), CU&&>); -static_assert(is_same_v(cu)), CU&&>); -static_assert(is_same_v(std::move(u))), CU&&>); -static_assert(is_same_v(std::move(cu))), CU&&>); - -static_assert(noexcept(forward_like(u))); - -static_assert(is_same_v(u)), U&>); -static_assert(is_same_v(cu)), CU&>); -static_assert(is_same_v(std::move(u))), U&&>); -static_assert(is_same_v(std::move(cu))), CU&&>); - -struct NoCtorCopyMove { - NoCtorCopyMove() = delete; - NoCtorCopyMove(const NoCtorCopyMove&) = delete; - NoCtorCopyMove(NoCtorCopyMove&&) = delete; -}; - -static_assert(is_same_v(declval())), const NoCtorCopyMove&&>); -static_assert(is_same_v(declval())), const NoCtorCopyMove&>); -static_assert(is_same_v(declval())), NoCtorCopyMove&&>); -static_assert(is_same_v(declval())), NoCtorCopyMove&>); - -static_assert(noexcept(forward_like(declval()))); - -constexpr bool test() { - { - int val = 1729; - auto&& result = forward_like(val); - static_assert(is_same_v); - assert(&result == &val); - } - { - int val = 1729; - auto&& result = forward_like(val); - static_assert(is_same_v); - assert(&result == &val); - } - { - int val = 1729; - auto&& result = forward_like(val); - static_assert(is_same_v); - assert(&result == &val); - } - { - int val = 1729; - auto&& result = forward_like(val); - static_assert(is_same_v); - assert(&result == &val); - } - return true; -} - -int main() { - assert(test()); - static_assert(test()); -} diff --git a/libcxx/test/std/utilities/utility/forward_like/forward_like.msvc/test.pass.cpp b/libcxx/test/std/utilities/utility/forward_like/forward_like.msvc/test.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/utilities/utility/forward_like/forward_like.msvc/test.pass.cpp +++ /dev/null @@ -1,13 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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, c++17, c++20 - -// Includes Microsoft's test that tests the entire header. - -#include "test.cpp"