[libc++] Implements concept destructible
authorMark de Wever <koraq@xs4all.nl>
Tue, 24 Nov 2020 15:12:34 +0000 (16:12 +0100)
committerMark de Wever <koraq@xs4all.nl>
Sat, 23 Jan 2021 17:17:25 +0000 (18:17 +0100)
Implements parts of:
- P0898R3 Standard Library Concepts
- P1754 Rename concepts to standard_case for C++20, while we still can

Reviewed By: ldionne, miscco, #libc

Differential Revision: https://reviews.llvm.org/D91004

libcxx/docs/Cxx2aStatusPaperStatus.csv
libcxx/include/concepts
libcxx/test/std/concepts/concept.destructible/destructible.compile.pass.cpp [new file with mode: 0644]

index 495489c..efdcb1b 100644 (file)
@@ -43,7 +43,7 @@
 "`P0879R0 <https://wg21.link/P0879R0>`__","LWG","Constexpr for swap and swap related functions Also resolves LWG issue 2800.","Rapperswil","",""
 "`P0887R1 <https://wg21.link/P0887R1>`__","LWG","The identity metafunction","Rapperswil","|Complete|","8.0"
 "`P0892R2 <https://wg21.link/P0892R2>`__","CWG","explicit(bool)","Rapperswil","",""
-"`P0898R3 <https://wg21.link/P0898R3>`__","LWG","Standard Library Concepts","Rapperswil","",""
+"`P0898R3 <https://wg21.link/P0898R3>`__","LWG","Standard Library Concepts","Rapperswil","|In Progress|",""
 "`P0935R0 <https://wg21.link/P0935R0>`__","LWG","Eradicating unnecessarily explicit default constructors from the standard library","Rapperswil","|Complete|","12.0"
 "`P0941R2 <https://wg21.link/P0941R2>`__","CWG","Integrating feature-test macros into the C++ WD","Rapperswil","|In Progress|",""
 "`P1023R0 <https://wg21.link/P1023R0>`__","LWG","constexpr comparison operators for std::array","Rapperswil","|Complete|","8.0"
 "`P1651 <https://wg21.link/P1651>`__","LWG","bind_front should not unwrap reference_wrapper","Cologne","",""
 "`P1652 <https://wg21.link/P1652>`__","LWG","Printf corner cases in std::format","Cologne","",""
 "`P1661 <https://wg21.link/P1661>`__","LWG","Remove dedicated precalculated hash lookup interface","Cologne","|Nothing To Do|",""
-"`P1754 <https://wg21.link/P1754>`__","LWG","Rename concepts to standard_case for C++20, while we still can","Cologne","",""
+"`P1754 <https://wg21.link/P1754>`__","LWG","Rename concepts to standard_case for C++20, while we still can","Cologne","|In Progress|",""
 "","","","","",""
 "`P0883 <https://wg21.link/P0883>`__","LWG","Fixing Atomic Initialization","Belfast","* *",""
 "`P1391 <https://wg21.link/P1391>`__","LWG","Range constructor for std::string_view","Belfast","* *",""
index 047e2c2..cf5f9d6 100644 (file)
@@ -157,6 +157,11 @@ concept __same_as_impl = _VSTD::_IsSame<_Tp, _Up>::value;
 template<class _Tp, class _Up>
 concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
 
+// [concept.destructible]
+
+template<class _Tp>
+concept destructible = _VSTD::is_nothrow_destructible_v<_Tp>;
+
 #endif //_LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/test/std/concepts/concept.destructible/destructible.compile.pass.cpp b/libcxx/test/std/concepts/concept.destructible/destructible.compile.pass.cpp
new file mode 100644 (file)
index 0000000..709972a
--- /dev/null
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+// UNSUPPORTED: libcpp-no-concepts
+
+// template<class T>
+// concept destructible = is_nothrow_destructible_v<T>;
+
+#include <concepts>
+#include <type_traits>
+
+struct Empty {};
+
+struct Defaulted {
+  ~Defaulted() = default;
+};
+struct Deleted {
+  ~Deleted() = delete;
+};
+
+struct Noexcept {
+  ~Noexcept() noexcept;
+};
+struct NoexceptTrue {
+  ~NoexceptTrue() noexcept(true);
+};
+struct NoexceptFalse {
+  ~NoexceptFalse() noexcept(false);
+};
+
+// Since C++17 dynamic exception specifications are no longer
+// part of the standard.
+struct Throw {
+  ~Throw() throw();
+};
+
+struct Protected {
+protected:
+  ~Protected() = default;
+};
+struct Private {
+private:
+  ~Private() = default;
+};
+
+template <class T>
+struct NoexceptDependant {
+  ~NoexceptDependant() noexcept(std::is_same_v<T, int>);
+};
+
+template <class T>
+void test() {
+  static_assert(std::destructible<T> == std::is_nothrow_destructible_v<T>);
+}
+
+void test() {
+  test<Empty>();
+
+  test<Defaulted>();
+  test<Deleted>();
+
+  test<Noexcept>();
+  test<NoexceptTrue>();
+  test<NoexceptFalse>();
+
+  test<Throw>();
+
+  test<Protected>();
+  test<Private>();
+
+  test<NoexceptDependant<int> >();
+  test<NoexceptDependant<double> >();
+
+  test<bool>();
+  test<char>();
+  test<int>();
+  test<double>();
+}
+
+// Required for MSVC internal test runner compatibility.
+int main(int, char**) { return 0; }