Skip to content

Commit 838c50f

Browse files
committed
Make forward_list constexpr as part of P3372R3
1 parent d8bfb47 commit 838c50f

File tree

74 files changed

+7776
-444
lines changed

Some content is hidden

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

74 files changed

+7776
-444
lines changed

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,11 @@ Status
418418
---------------------------------------------------------- -----------------
419419
``__cpp_lib_bitset`` ``202306L``
420420
---------------------------------------------------------- -----------------
421+
<<<<<<< HEAD
421422
``__cpp_lib_constexpr_algorithms`` ``202306L``
423+
=======
424+
``__cpp_lib_constexpr_forward_list`` ``202502L``
425+
>>>>>>> 3e1b3b8f0316 (Make forward_list constexpr as part of P3372R3)
422426
---------------------------------------------------------- -----------------
423427
``__cpp_lib_constexpr_new`` ``202406L``
424428
---------------------------------------------------------- -----------------

libcxx/include/__memory/allocation_guard.h

Lines changed: 11 additions & 9 deletions
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

Lines changed: 268 additions & 202 deletions
Large diffs are not rendered by default.

libcxx/include/version

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ __cpp_lib_constexpr_charconv 202207L <charconv>
6868
__cpp_lib_constexpr_cmath 202202L <cmath> <cstdlib>
6969
__cpp_lib_constexpr_complex 201711L <complex>
7070
__cpp_lib_constexpr_dynamic_alloc 201907L <memory>
71+
__cpp_lib_constexpr_forward_list 202502L <forward_list>
7172
__cpp_lib_constexpr_functional 201907L <functional>
7273
__cpp_lib_constexpr_iterator 201811L <iterator>
7374
__cpp_lib_constexpr_memory 202202L <memory>
@@ -543,6 +544,7 @@ __cpp_lib_void_t 201411L <type_traits>
543544
# define __cpp_lib_bitset 202306L
544545
# undef __cpp_lib_constexpr_algorithms
545546
# define __cpp_lib_constexpr_algorithms 202306L
547+
# define __cpp_lib_constexpr_forward_list 202502L
546548
# if !defined(_LIBCPP_ABI_VCRUNTIME)
547549
# define __cpp_lib_constexpr_new 202406L
548550
# endif

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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 11 additions & 2 deletions
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

Lines changed: 13 additions & 3 deletions
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

Lines changed: 11 additions & 2 deletions
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

Lines changed: 11 additions & 2 deletions
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

Lines changed: 11 additions & 2 deletions
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
}

0 commit comments

Comments
 (0)