Skip to content

Commit c6a1c3d

Browse files
committed
Make forward_list constexpr as part of P3372R3
1 parent f5f5286 commit c6a1c3d

File tree

76 files changed

+1191
-462
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1191
-462
lines changed

libcxx/docs/FeatureTestMacroTable.rst

+2
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ Status
416416
---------------------------------------------------------- -----------------
417417
``__cpp_lib_bitset`` ``202306L``
418418
---------------------------------------------------------- -----------------
419+
``__cpp_lib_constexpr_forward_list`` ``202502L``
420+
---------------------------------------------------------- -----------------
419421
``__cpp_lib_constexpr_new`` ``202406L``
420422
---------------------------------------------------------- -----------------
421423
``__cpp_lib_constrained_equality`` *unimplemented*

libcxx/include/__memory/allocation_guard.h

+11-9
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,26 @@ struct __allocation_guard {
4949
using _Size _LIBCPP_NODEBUG = typename allocator_traits<_Alloc>::size_type;
5050

5151
template <class _AllocT> // we perform the allocator conversion inside the constructor
52-
_LIBCPP_HIDE_FROM_ABI explicit __allocation_guard(_AllocT __alloc, _Size __n)
52+
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __allocation_guard(_AllocT __alloc, _Size __n)
5353
: __alloc_(std::move(__alloc)),
5454
__n_(__n),
5555
__ptr_(allocator_traits<_Alloc>::allocate(__alloc_, __n_)) // initialization order is important
5656
{}
5757

58-
_LIBCPP_HIDE_FROM_ABI ~__allocation_guard() _NOEXCEPT { __destroy(); }
58+
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI ~__allocation_guard() _NOEXCEPT { __destroy(); }
5959

60-
_LIBCPP_HIDE_FROM_ABI __allocation_guard(const __allocation_guard&) = delete;
61-
_LIBCPP_HIDE_FROM_ABI __allocation_guard(__allocation_guard&& __other) _NOEXCEPT
60+
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __allocation_guard(const __allocation_guard&) = delete;
61+
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __allocation_guard(__allocation_guard&& __other) _NOEXCEPT
6262
: __alloc_(std::move(__other.__alloc_)),
6363
__n_(__other.__n_),
6464
__ptr_(__other.__ptr_) {
6565
__other.__ptr_ = nullptr;
6666
}
6767

68-
_LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(const __allocation_guard& __other) = delete;
69-
_LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(__allocation_guard&& __other) _NOEXCEPT {
68+
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __allocation_guard&
69+
operator=(const __allocation_guard& __other) = delete;
70+
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __allocation_guard&
71+
operator=(__allocation_guard&& __other) _NOEXCEPT {
7072
if (std::addressof(__other) != this) {
7173
__destroy();
7274

@@ -79,17 +81,17 @@ struct __allocation_guard {
7981
return *this;
8082
}
8183

82-
_LIBCPP_HIDE_FROM_ABI _Pointer
84+
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI _Pointer
8385
__release_ptr() _NOEXCEPT { // not called __release() because it's a keyword in objective-c++
8486
_Pointer __tmp = __ptr_;
8587
__ptr_ = nullptr;
8688
return __tmp;
8789
}
8890

89-
_LIBCPP_HIDE_FROM_ABI _Pointer __get() const _NOEXCEPT { return __ptr_; }
91+
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI _Pointer __get() const _NOEXCEPT { return __ptr_; }
9092

9193
private:
92-
_LIBCPP_HIDE_FROM_ABI void __destroy() _NOEXCEPT {
94+
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __destroy() _NOEXCEPT {
9395
if (__ptr_ != nullptr) {
9496
allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __n_);
9597
}

libcxx/include/forward_list

+273-203
Large diffs are not rendered by default.

libcxx/include/version

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ __cpp_lib_constexpr_charconv 202207L <charconv>
6666
__cpp_lib_constexpr_cmath 202202L <cmath> <cstdlib>
6767
__cpp_lib_constexpr_complex 201711L <complex>
6868
__cpp_lib_constexpr_dynamic_alloc 201907L <memory>
69+
__cpp_lib_constexpr_forward_list 202502L <forward_list>
6970
__cpp_lib_constexpr_functional 201907L <functional>
7071
__cpp_lib_constexpr_iterator 201811L <iterator>
7172
__cpp_lib_constexpr_memory 202202L <memory>
@@ -536,6 +537,7 @@ __cpp_lib_void_t 201411L <type_traits>
536537
# undef __cpp_lib_bind_front
537538
# define __cpp_lib_bind_front 202306L
538539
# define __cpp_lib_bitset 202306L
540+
# define __cpp_lib_constexpr_forward_list 202502L
539541
# if !defined(_LIBCPP_ABI_VCRUNTIME)
540542
# define __cpp_lib_constexpr_new 202406L
541543
# endif

libcxx/test/std/containers/Emplaceable.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,41 @@
1515
#if TEST_STD_VER >= 11
1616

1717
class Emplaceable {
18-
Emplaceable(const Emplaceable&);
19-
Emplaceable& operator=(const Emplaceable&);
18+
Emplaceable(const Emplaceable&) = delete;
19+
Emplaceable& operator=(const Emplaceable&) = delete;
2020

2121
int int_;
2222
double double_;
2323

2424
public:
25-
Emplaceable() : int_(0), double_(0) {}
26-
Emplaceable(int i, double d) : int_(i), double_(d) {}
27-
Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
25+
TEST_CONSTEXPR_CXX20 Emplaceable() : int_(0), double_(0) {}
26+
TEST_CONSTEXPR_CXX20 Emplaceable(int i, double d) : int_(i), double_(d) {}
27+
TEST_CONSTEXPR_CXX20 Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
2828
x.int_ = 0;
2929
x.double_ = 0;
3030
}
31-
Emplaceable& operator=(Emplaceable&& x) {
31+
TEST_CONSTEXPR_CXX20 Emplaceable& operator=(Emplaceable&& x) {
3232
int_ = x.int_;
3333
x.int_ = 0;
3434
double_ = x.double_;
3535
x.double_ = 0;
3636
return *this;
3737
}
3838

39-
bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
40-
bool operator<(const Emplaceable& x) const { return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_); }
39+
TEST_CONSTEXPR_CXX20 bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
40+
TEST_CONSTEXPR_CXX20 bool operator<(const Emplaceable& x) const {
41+
return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);
42+
}
4143

42-
int get() const { return int_; }
44+
TEST_CONSTEXPR_CXX20 int get() const { return int_; }
4345
};
4446

4547
template <>
4648
struct std::hash<Emplaceable> {
4749
typedef Emplaceable argument_type;
4850
typedef std::size_t result_type;
4951

50-
std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
52+
TEST_CONSTEXPR_CXX20 std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
5153
};
5254

5355
#endif // TEST_STD_VER >= 11

libcxx/test/std/containers/sequences/forwardlist/compare.three_way.pass.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
// template<class T, class Allocator>
1313
// synth-three-way-result<T> operator<=>(const forward_list<T, Allocator>& x,
14-
// const forward_list<T, Allocator>& y);
14+
// const forward_list<T, Allocator>& y); // constexpr since C++26
1515

1616
#include <cassert>
1717
#include <forward_list>
@@ -20,6 +20,9 @@
2020

2121
int main(int, char**) {
2222
assert(test_sequence_container_spaceship<std::forward_list>());
23-
// `std::forward_list` is not constexpr, so no `static_assert` test here.
23+
#if TEST_STD_VER >= 26
24+
static_assert(test_sequence_container_spaceship<std::forward_list>());
25+
#endif
26+
2427
return 0;
2528
}

libcxx/test/std/containers/sequences/forwardlist/empty.pass.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
// class forward_list
1212

13-
// bool empty() const noexcept;
13+
// bool empty() const noexcept; // constexpr since C++26
1414

1515
#include <forward_list>
1616
#include <cassert>
1717

1818
#include "test_macros.h"
1919
#include "min_allocator.h"
2020

21-
int main(int, char**) {
21+
TEST_CONSTEXPR_CXX26 bool test() {
2222
{
2323
typedef std::forward_list<int> C;
2424
C c;
@@ -42,5 +42,14 @@ int main(int, char**) {
4242
}
4343
#endif
4444

45+
return true;
46+
}
47+
48+
int main(int, char**) {
49+
assert(test());
50+
#if TEST_STD_VER >= 26
51+
static_assert(test());
52+
#endif
53+
4554
return 0;
4655
}

libcxx/test/std/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88

99
// <forward_list>
1010

11-
// reference front();
12-
// const_reference front() const;
11+
// reference front(); // constexpr since C++26
12+
// const_reference front() const; // constexpr since C++26
1313

1414
#include <forward_list>
1515
#include <cassert>
1616
#include <iterator>
1717

18+
#include "test_allocator.h"
1819
#include "test_macros.h"
1920
#include "min_allocator.h"
2021

21-
int main(int, char**) {
22+
TEST_CONSTEXPR_CXX26 bool test() {
2223
{
2324
typedef int T;
2425
typedef std::forward_list<T> C;
@@ -58,5 +59,14 @@ int main(int, char**) {
5859
}
5960
#endif
6061

62+
return true;
63+
}
64+
65+
int main(int, char**) {
66+
assert(test());
67+
#if TEST_STD_VER >= 26
68+
static_assert(test());
69+
#endif
70+
6171
return 0;
6272
}

libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.compile.fail.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
// <forward_list>
1010

11-
// explicit forward_list(const allocator_type& a);
11+
// explicit forward_list(const allocator_type& a); // constexpr since C++26
1212

1313
#include <forward_list>
1414
#include <cassert>
1515

1616
#include "test_allocator.h"
1717
#include "../../../NotConstructible.h"
1818

19-
int main(int, char**) {
19+
TEST_CONSTEXPR_CXX26 bool test() {
2020
{
2121
typedef test_allocator<NotConstructible> A;
2222
typedef A::value_type T;
@@ -26,5 +26,14 @@ int main(int, char**) {
2626
assert(c.empty());
2727
}
2828

29+
return true;
30+
}
31+
32+
int main(int, char**) {
33+
test();
34+
#if TEST_STD_VER >= 26
35+
static_assert(test());
36+
#endif
37+
2938
return 0;
3039
}

libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// <forward_list>
1010

11-
// explicit forward_list(const allocator_type& a);
11+
// explicit forward_list(const allocator_type& a); // constexpr since C++26
1212

1313
#include <forward_list>
1414
#include <cassert>
@@ -18,7 +18,7 @@
1818
#include "../../../NotConstructible.h"
1919
#include "min_allocator.h"
2020

21-
int main(int, char**) {
21+
TEST_CONSTEXPR_CXX26 bool test() {
2222
{
2323
typedef test_allocator<NotConstructible> A;
2424
typedef A::value_type T;
@@ -46,5 +46,14 @@ int main(int, char**) {
4646
}
4747
#endif
4848

49+
return true;
50+
}
51+
52+
int main(int, char**) {
53+
assert(test());
54+
#if TEST_STD_VER >= 26
55+
static_assert(test());
56+
#endif
57+
4958
return 0;
5059
}

libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// <forward_list>
1010

11-
// forward_list& operator=(const forward_list& x);
11+
// forward_list& operator=(const forward_list& x); // constexpr since C++26
1212

1313
#include <forward_list>
1414
#include <cassert>
@@ -18,7 +18,7 @@
1818
#include "test_allocator.h"
1919
#include "min_allocator.h"
2020

21-
int main(int, char**) {
21+
TEST_CONSTEXPR_CXX26 bool test() {
2222
{
2323
typedef int T;
2424
typedef test_allocator<int> A;
@@ -143,5 +143,14 @@ int main(int, char**) {
143143
}
144144
#endif
145145

146+
return true;
147+
}
148+
149+
int main(int, char**) {
150+
assert(test());
151+
#if TEST_STD_VER >= 26
152+
static_assert(test());
153+
#endif
154+
146155
return 0;
147156
}

libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// <forward_list>
1212

13-
// void assign(initializer_list<value_type> il);
13+
// void assign(initializer_list<value_type> il); // constexpr since C++26
1414

1515
#include <forward_list>
1616
#include <cassert>
@@ -19,7 +19,7 @@
1919
#include "test_macros.h"
2020
#include "min_allocator.h"
2121

22-
int main(int, char**) {
22+
TEST_CONSTEXPR_CXX26 bool test() {
2323
{
2424
typedef int T;
2525
typedef std::forward_list<T> C;
@@ -65,5 +65,14 @@ int main(int, char**) {
6565
assert(n == 4);
6666
}
6767

68+
return true;
69+
}
70+
71+
int main(int, char**) {
72+
assert(test());
73+
#if TEST_STD_VER >= 26
74+
static_assert(test());
75+
#endif
76+
6877
return 0;
6978
}

libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// <forward_list>
1212

13-
// forward_list& operator=(forward_list&& x);
13+
// forward_list& operator=(forward_list&& x); // constexpr since C++26
1414

1515
#include <forward_list>
1616
#include <cassert>
@@ -21,7 +21,7 @@
2121
#include "MoveOnly.h"
2222
#include "min_allocator.h"
2323

24-
int main(int, char**) {
24+
TEST_CONSTEXPR_CXX26 bool test() {
2525
{
2626
typedef MoveOnly T;
2727
typedef test_allocator<T> A;
@@ -194,5 +194,14 @@ int main(int, char**) {
194194
assert(c0.empty());
195195
}
196196

197+
return true;
198+
}
199+
200+
int main(int, char**) {
201+
assert(test());
202+
#if TEST_STD_VER >= 26
203+
static_assert(test());
204+
#endif
205+
197206
return 0;
198207
}

0 commit comments

Comments
 (0)