[libcxx-commits] [libcxx] a8e0636 - [libc++] Implements concept destructible

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 23 09:17:31 PST 2021


Author: Mark de Wever
Date: 2021-01-23T18:17:25+01:00
New Revision: a8e06361ddba6a25fb0c27596aaa03c5423d1868

URL: https://github.com/llvm/llvm-project/commit/a8e06361ddba6a25fb0c27596aaa03c5423d1868
DIFF: https://github.com/llvm/llvm-project/commit/a8e06361ddba6a25fb0c27596aaa03c5423d1868.diff

LOG: [libc++] Implements concept destructible

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

Added: 
    libcxx/test/std/concepts/concept.destructible/destructible.compile.pass.cpp

Modified: 
    libcxx/docs/Cxx2aStatusPaperStatus.csv
    libcxx/include/concepts

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/Cxx2aStatusPaperStatus.csv b/libcxx/docs/Cxx2aStatusPaperStatus.csv
index 495489c4c4c8..efdcb1b67161 100644
--- a/libcxx/docs/Cxx2aStatusPaperStatus.csv
+++ b/libcxx/docs/Cxx2aStatusPaperStatus.csv
@@ -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"
@@ -131,7 +131,7 @@
 "`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","* *",""

diff  --git a/libcxx/include/concepts b/libcxx/include/concepts
index 047e2c290f4e..cf5f9d63971f 100644
--- a/libcxx/include/concepts
+++ b/libcxx/include/concepts
@@ -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
index 000000000000..709972a391cb
--- /dev/null
+++ b/libcxx/test/std/concepts/concept.destructible/destructible.compile.pass.cpp
@@ -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; }


        


More information about the libcxx-commits mailing list