diff --git a/libcxx/docs/Cxx2aStatus.rst b/libcxx/docs/Cxx2aStatus.rst --- a/libcxx/docs/Cxx2aStatus.rst +++ b/libcxx/docs/Cxx2aStatus.rst @@ -42,7 +42,7 @@ .. [#note-P0600] P0600: The missing bits in P0600 are in |sect|\ [mem.res.class], |sect|\ [mem.poly.allocator.class], and |sect|\ [container.node.overview]. .. [#note-P0966] P0966: It was previously erroneously marked as complete in version 8.0. See `bug 45368 `__. - .. [#note-P0619] P0619: Only sections D.8, D.9, and D.10 are implemented. Sections D.4, D.7, D.11, D.12, and D.14 remain undone. + .. [#note-P0619] P0619: Only sections D.8, D.9, D.10 and D.13 are implemented. Sections D.4, D.7, D.11, D.12, and D.14 remain undone. .. [#note-P0883] P0883: shared_ptr and floating-point changes weren't applied as they themselves aren't implemented yet. diff --git a/libcxx/docs/UsingLibcxx.rst b/libcxx/docs/UsingLibcxx.rst --- a/libcxx/docs/UsingLibcxx.rst +++ b/libcxx/docs/UsingLibcxx.rst @@ -266,6 +266,9 @@ **_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR**: This macro is used to re-enable `raw_storage_iterator`. +**_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS**: + This macro is used to re-enable `is_literal_type`, `is_literal_type_v`, + `result_of` and `result_of_t`. Libc++ Extensions ================= diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1359,6 +1359,7 @@ #define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS #define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS #define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR +#define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS #endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES #if !defined(__cpp_deduction_guides) || __cpp_deduction_guides < 201611 diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -99,7 +99,7 @@ template struct is_trivial; template struct is_trivially_copyable; template struct is_standard_layout; - template struct is_literal_type; + template struct is_literal_type; // Deprecated in C++17; removed in C++20 template struct is_empty; template struct is_polymorphic; template struct is_abstract; @@ -165,8 +165,8 @@ template struct decay; template struct common_type; template struct underlying_type; - template class result_of; // undefined - template class result_of; + template class result_of; // undefined; deprecated in C++17; removed in C++20 + template class result_of; // deprecated in C++17; removed in C++20 template struct invoke_result; // C++17 // const-volatile modifications: @@ -233,7 +233,7 @@ template using underlying_type_t = typename underlying_type::type; // C++14 template - using result_of_t = typename result_of::type; // C++14 + using result_of_t = typename result_of::type; // C++14; deprecated in C++17; removed in C++20 template using invoke_result_t = typename invoke_result::type; // C++17 @@ -302,7 +302,7 @@ template inline constexpr bool is_pod_v = is_pod::value; // C++17 template inline constexpr bool is_literal_type_v - = is_literal_type::value; // C++17 + = is_literal_type::value; // C++17; deprecated in C++17; removed in C++20 template inline constexpr bool is_empty_v = is_empty::value; // C++17 template inline constexpr bool is_polymorphic_v @@ -3677,15 +3677,17 @@ // is_literal_type; -template struct _LIBCPP_TEMPLATE_VIS is_literal_type +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS) +template struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 is_literal_type : public integral_constant {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template -_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_literal_type_v +_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_literal_type_v = is_literal_type<_Tp>::value; -#endif +#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS) // is_standard_layout; @@ -4003,7 +4005,8 @@ // result_of -template class result_of; +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS) +template class _LIBCPP_DEPRECATED_IN_CXX17 result_of; #ifndef _LIBCPP_CXX03_LANG @@ -4091,8 +4094,9 @@ #endif // C++03 #if _LIBCPP_STD_VER > 11 -template using result_of_t = typename result_of<_Tp>::type; -#endif +template using result_of_t _LIBCPP_DEPRECATED_IN_CXX17 = typename result_of<_Tp>::type; +#endif // _LIBCPP_STD_VER > 11 +#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS) #if _LIBCPP_STD_VER > 14 diff --git a/libcxx/test/std/atomics/atomics.types.generic/standard_layout.compile.pass.cpp b/libcxx/test/std/atomics/atomics.types.generic/standard_layout.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/atomics/atomics.types.generic/standard_layout.compile.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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: libcpp-has-no-threads +// UNSUPPORTED: c++03 + +// + +#include +#include +#include + +#include "test_macros.h" +#include "atomic_helpers.h" + +template +struct CheckStandardLayout { + void operator()() const { + typedef std::atomic Atomic; + static_assert(std::is_standard_layout::value, ""); + } +}; + +int main(int, char**) { + TestEachIntegralType()(); + TestEachFloatingPointType()(); + TestEachPointerType()(); + + return 0; +} diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h deleted file mode 100644 --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h +++ /dev/null @@ -1,131 +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 -// -//===----------------------------------------------------------------------===// - -#ifndef ATOMIC_HELPERS_H -#define ATOMIC_HELPERS_H - -#include - -#include "test_macros.h" - -struct UserAtomicType -{ - int i; - - explicit UserAtomicType(int d = 0) TEST_NOEXCEPT : i(d) {} - - friend bool operator==(const UserAtomicType& x, const UserAtomicType& y) - { return x.i == y.i; } -}; - -/* - -Enable these once we have P0528 - -struct WeirdUserAtomicType -{ - char i, j, k; // the 3 chars of doom - - explicit WeirdUserAtomicType(int d = 0) TEST_NOEXCEPT : i(d) {} - - friend bool operator==(const WeirdUserAtomicType& x, const WeirdUserAtomicType& y) - { return x.i == y.i; } -}; - -struct PaddedUserAtomicType -{ - char i; int j; // probably lock-free? - - explicit PaddedUserAtomicType(int d = 0) TEST_NOEXCEPT : i(d) {} - - friend bool operator==(const PaddedUserAtomicType& x, const PaddedUserAtomicType& y) - { return x.i == y.i; } -}; - -*/ - -struct LargeUserAtomicType -{ - int a[128]; /* decidedly not lock-free */ - - LargeUserAtomicType(int d = 0) TEST_NOEXCEPT - { - for (auto && e : a) - e = d++; - } - - friend bool operator==(LargeUserAtomicType const& x, LargeUserAtomicType const& y) TEST_NOEXCEPT - { - for (int i = 0; i < 128; ++i) - if (x.a[i] != y.a[i]) - return false; - return true; - } -}; - -template < template class TestFunctor > -struct TestEachIntegralType { - void operator()() const { - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - TestFunctor(); -#if TEST_STD_VER > 17 && defined(__cpp_char8_t) - TestFunctor()(); -#endif -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - TestFunctor()(); - TestFunctor()(); -#endif - TestFunctor< int8_t>()(); - TestFunctor< uint8_t>()(); - TestFunctor< int16_t>()(); - TestFunctor()(); - TestFunctor< int32_t>()(); - TestFunctor()(); - TestFunctor< int64_t>()(); - TestFunctor()(); - } -}; - -template < template class TestFunctor > -struct TestEachAtomicType { - void operator()() const { - TestEachIntegralType()(); - TestFunctor()(); - /* - Note: These aren't going to be lock-free, - so some libatomic.a is necessary. To handle - the case where the support functions are - missing, all tests that use this file should add: - XFAIL: !non-lockfree-atomics - */ - TestFunctor()(); -/* - Enable these once we have P0528 - - TestFunctor()(); - TestFunctor()(); -*/ - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - TestFunctor()(); - } -}; - - -#endif // ATOMIC_HELPER_H diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp --- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp @@ -21,42 +21,37 @@ #include "atomic_helpers.h" struct UserType { - int i; + int i; - UserType() noexcept {} - constexpr explicit UserType(int d) noexcept : i(d) {} + UserType() noexcept {} + constexpr explicit UserType(int d) noexcept : i(d) {} - friend bool operator==(const UserType& x, const UserType& y) { - return x.i == y.i; - } + friend bool operator==(const UserType& x, const UserType& y) { return x.i == y.i; } }; template struct TestFunc { - void operator()() const { - typedef std::atomic Atomic; - static_assert(std::is_literal_type::value, ""); - constexpr Tp t(42); - { - constexpr Atomic a(t); - assert(a == t); - } - { - constexpr Atomic a{t}; - assert(a == t); - } - { - constexpr Atomic a = ATOMIC_VAR_INIT(t); - assert(a == t); - } + void operator()() const { + typedef std::atomic Atomic; + constexpr Tp t(42); + { + constexpr Atomic a(t); + assert(a == t); + } + { + constexpr Atomic a{t}; + assert(a == t); } + { + constexpr Atomic a = ATOMIC_VAR_INIT(t); + assert(a == t); + } + } }; - -int main(int, char**) -{ - TestFunc()(); - TestEachIntegralType()(); +int main(int, char**) { + TestFunc()(); + TestEachIntegralType()(); return 0; } diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/dtor.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/dtor.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/dtor.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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: libcpp-has-no-threads +// UNSUPPORTED: c++03 + +// + +// constexpr atomic::~atomic() + +#include +#include +#include + +#include "test_macros.h" +#include "atomic_helpers.h" + +template +struct CheckTriviallyDestructible { + void operator()() const { + typedef std::atomic Atomic; + static_assert(std::is_trivially_destructible::value, ""); + } +}; + +int main(int, char**) { + TestEachIntegralType()(); + TestEachFloatingPointType()(); + TestEachPointerType()(); + + return 0; +} diff --git a/libcxx/test/std/utilities/function.objects/func.invoke/invoke.pass.cpp b/libcxx/test/std/utilities/function.objects/func.invoke/invoke.pass.cpp --- a/libcxx/test/std/utilities/function.objects/func.invoke/invoke.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.invoke/invoke.pass.cpp @@ -10,6 +10,9 @@ // +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS + // template // invoke_result_t invoke(F&& f, Args&&... args) // C++17 // noexcept(is_nothrow_invocable_v<_Fn, _Args...>); diff --git a/libcxx/test/std/utilities/function.objects/func.invoke/invoke_constexpr.pass.cpp b/libcxx/test/std/utilities/function.objects/func.invoke/invoke_constexpr.pass.cpp --- a/libcxx/test/std/utilities/function.objects/func.invoke/invoke_constexpr.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.invoke/invoke_constexpr.pass.cpp @@ -10,6 +10,9 @@ // +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS + // template // constexpr // constexpr in C++20 // invoke_result_t invoke(F&& f, Args&&... args) diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp --- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp @@ -261,39 +261,6 @@ } } - -// The example code specified in Note B for common_type -namespace note_b_example { - -typedef bool (&PF1)(); -typedef short (*PF2)(long); - -struct S { - operator PF2() const; - double operator()(char, int&); - void fn(long) const; - char data; -}; - -typedef void (S::*PMF)(long) const; -typedef char S::*PMD; - -using std::is_same; -using std::result_of; -using std::unique_ptr; - -static_assert((is_same::type, short>::value), "Error!"); -static_assert((is_same::type, double>::value), "Error!"); -static_assert((is_same::type, bool>::value), "Error!"); -static_assert((is_same, int)>::type, void>::value), "Error!"); -#if TEST_STD_VER >= 11 -static_assert((is_same::type, char&&>::value), "Error!"); -#endif -static_assert((is_same::type, const char&>::value), "Error!"); - -} // namespace note_b_example - - int main(int, char**) { static_assert((std::is_same::type, int>::value), ""); diff --git a/libcxx/test/std/utilities/any/any.class/not_literal_type.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.deprecated.fail.cpp rename from libcxx/test/std/utilities/any/any.class/not_literal_type.pass.cpp rename to libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.deprecated.fail.cpp --- a/libcxx/test/std/utilities/any/any.class/not_literal_type.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.deprecated.fail.cpp @@ -7,18 +7,16 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14 +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS -// +// type_traits -// [Note any is a not a literal type --end note] +// result_of -#include #include #include "test_macros.h" int main(int, char**) { - static_assert(!std::is_literal_type::value, ""); - - return 0; + [[maybe_unused]] std::result_of a; // expected-warning {{'result_of' is deprecated}} } diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp --- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp @@ -10,6 +10,9 @@ // result_of +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS + #include #include #include diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp --- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp @@ -12,6 +12,9 @@ // // result_of +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS + #include #include #include diff --git a/libcxx/test/std/utilities/any/any.class/not_literal_type.pass.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.deprecated.fail.cpp rename from libcxx/test/std/utilities/any/any.class/not_literal_type.pass.cpp rename to libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.deprecated.fail.cpp --- a/libcxx/test/std/utilities/any/any.class/not_literal_type.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.deprecated.fail.cpp @@ -7,18 +7,18 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14 +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS -// +// type_traits -// [Note any is a not a literal type --end note] +// is_literal_type -#include #include #include "test_macros.h" int main(int, char**) { - static_assert(!std::is_literal_type::value, ""); + static_assert(std::is_literal_type::value, ""); // expected-warning {{'is_literal_type' is deprecated}} return 0; } diff --git a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp --- a/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp @@ -10,6 +10,9 @@ // is_literal_type +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS + #include #include // for std::nullptr_t #include "test_macros.h" diff --git a/libcxx/test/support/atomic_helpers.h b/libcxx/test/support/atomic_helpers.h new file mode 100644 --- /dev/null +++ b/libcxx/test/support/atomic_helpers.h @@ -0,0 +1,142 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef ATOMIC_HELPERS_H +#define ATOMIC_HELPERS_H + +#include + +#include "test_macros.h" + +struct UserAtomicType { + int i; + + explicit UserAtomicType(int d = 0) TEST_NOEXCEPT : i(d) {} + + friend bool operator==(const UserAtomicType& x, const UserAtomicType& y) { return x.i == y.i; } +}; + +/* + +Enable these once we have P0528 + +struct WeirdUserAtomicType +{ + char i, j, k; // the 3 chars of doom + + explicit WeirdUserAtomicType(int d = 0) TEST_NOEXCEPT : i(d) {} + + friend bool operator==(const WeirdUserAtomicType& x, const WeirdUserAtomicType& y) + { return x.i == y.i; } +}; + +struct PaddedUserAtomicType +{ + char i; int j; // probably lock-free? + + explicit PaddedUserAtomicType(int d = 0) TEST_NOEXCEPT : i(d) {} + + friend bool operator==(const PaddedUserAtomicType& x, const PaddedUserAtomicType& y) + { return x.i == y.i; } +}; + +*/ + +struct LargeUserAtomicType { + int a[128]; /* decidedly not lock-free */ + + LargeUserAtomicType(int d = 0) TEST_NOEXCEPT { + for (auto&& e : a) + e = d++; + } + + friend bool operator==(LargeUserAtomicType const& x, LargeUserAtomicType const& y) TEST_NOEXCEPT { + for (int i = 0; i < 128; ++i) + if (x.a[i] != y.a[i]) + return false; + return true; + } +}; + +template