Skip to content

Commit a8e0636

Browse files
committed
[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
1 parent 757b93b commit a8e0636

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

libcxx/docs/Cxx2aStatusPaperStatus.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"`P0879R0 <https://wg21.link/P0879R0>`__","LWG","Constexpr for swap and swap related functions Also resolves LWG issue 2800.","Rapperswil","",""
4444
"`P0887R1 <https://wg21.link/P0887R1>`__","LWG","The identity metafunction","Rapperswil","|Complete|","8.0"
4545
"`P0892R2 <https://wg21.link/P0892R2>`__","CWG","explicit(bool)","Rapperswil","",""
46-
"`P0898R3 <https://wg21.link/P0898R3>`__","LWG","Standard Library Concepts","Rapperswil","",""
46+
"`P0898R3 <https://wg21.link/P0898R3>`__","LWG","Standard Library Concepts","Rapperswil","|In Progress|",""
4747
"`P0935R0 <https://wg21.link/P0935R0>`__","LWG","Eradicating unnecessarily explicit default constructors from the standard library","Rapperswil","|Complete|","12.0"
4848
"`P0941R2 <https://wg21.link/P0941R2>`__","CWG","Integrating feature-test macros into the C++ WD","Rapperswil","|In Progress|",""
4949
"`P1023R0 <https://wg21.link/P1023R0>`__","LWG","constexpr comparison operators for std::array","Rapperswil","|Complete|","8.0"
@@ -131,7 +131,7 @@
131131
"`P1651 <https://wg21.link/P1651>`__","LWG","bind_front should not unwrap reference_wrapper","Cologne","",""
132132
"`P1652 <https://wg21.link/P1652>`__","LWG","Printf corner cases in std::format","Cologne","",""
133133
"`P1661 <https://wg21.link/P1661>`__","LWG","Remove dedicated precalculated hash lookup interface","Cologne","|Nothing To Do|",""
134-
"`P1754 <https://wg21.link/P1754>`__","LWG","Rename concepts to standard_case for C++20, while we still can","Cologne","",""
134+
"`P1754 <https://wg21.link/P1754>`__","LWG","Rename concepts to standard_case for C++20, while we still can","Cologne","|In Progress|",""
135135
"","","","","",""
136136
"`P0883 <https://wg21.link/P0883>`__","LWG","Fixing Atomic Initialization","Belfast","* *",""
137137
"`P1391 <https://wg21.link/P1391>`__","LWG","Range constructor for std::string_view","Belfast","* *",""

libcxx/include/concepts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ concept __same_as_impl = _VSTD::_IsSame<_Tp, _Up>::value;
157157
template<class _Tp, class _Up>
158158
concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
159159

160+
// [concept.destructible]
161+
162+
template<class _Tp>
163+
concept destructible = _VSTD::is_nothrow_destructible_v<_Tp>;
164+
160165
#endif //_LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
161166

162167
_LIBCPP_END_NAMESPACE_STD
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
// UNSUPPORTED: libcpp-no-concepts
11+
12+
// template<class T>
13+
// concept destructible = is_nothrow_destructible_v<T>;
14+
15+
#include <concepts>
16+
#include <type_traits>
17+
18+
struct Empty {};
19+
20+
struct Defaulted {
21+
~Defaulted() = default;
22+
};
23+
struct Deleted {
24+
~Deleted() = delete;
25+
};
26+
27+
struct Noexcept {
28+
~Noexcept() noexcept;
29+
};
30+
struct NoexceptTrue {
31+
~NoexceptTrue() noexcept(true);
32+
};
33+
struct NoexceptFalse {
34+
~NoexceptFalse() noexcept(false);
35+
};
36+
37+
// Since C++17 dynamic exception specifications are no longer
38+
// part of the standard.
39+
struct Throw {
40+
~Throw() throw();
41+
};
42+
43+
struct Protected {
44+
protected:
45+
~Protected() = default;
46+
};
47+
struct Private {
48+
private:
49+
~Private() = default;
50+
};
51+
52+
template <class T>
53+
struct NoexceptDependant {
54+
~NoexceptDependant() noexcept(std::is_same_v<T, int>);
55+
};
56+
57+
template <class T>
58+
void test() {
59+
static_assert(std::destructible<T> == std::is_nothrow_destructible_v<T>);
60+
}
61+
62+
void test() {
63+
test<Empty>();
64+
65+
test<Defaulted>();
66+
test<Deleted>();
67+
68+
test<Noexcept>();
69+
test<NoexceptTrue>();
70+
test<NoexceptFalse>();
71+
72+
test<Throw>();
73+
74+
test<Protected>();
75+
test<Private>();
76+
77+
test<NoexceptDependant<int> >();
78+
test<NoexceptDependant<double> >();
79+
80+
test<bool>();
81+
test<char>();
82+
test<int>();
83+
test<double>();
84+
}
85+
86+
// Required for MSVC internal test runner compatibility.
87+
int main(int, char**) { return 0; }

0 commit comments

Comments
 (0)