Skip to content

Commit fb8898e

Browse files
committed
Make list constexpr as part of P3372R3
1 parent df7db44 commit fb8898e

File tree

68 files changed

+1550
-844
lines changed

Some content is hidden

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

68 files changed

+1550
-844
lines changed

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ Status
422422
---------------------------------------------------------- -----------------
423423
``__cpp_lib_constexpr_forward_list`` ``202502L``
424424
---------------------------------------------------------- -----------------
425+
``__cpp_lib_constexpr_list`` ``202502L``
426+
---------------------------------------------------------- -----------------
425427
``__cpp_lib_constexpr_new`` ``202406L``
426428
---------------------------------------------------------- -----------------
427429
``__cpp_lib_constexpr_queue`` ``202502L``

libcxx/include/list

Lines changed: 325 additions & 227 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
@@ -71,6 +71,7 @@ __cpp_lib_constexpr_dynamic_alloc 201907L <memory>
7171
__cpp_lib_constexpr_forward_list 202502L <forward_list>
7272
__cpp_lib_constexpr_functional 201907L <functional>
7373
__cpp_lib_constexpr_iterator 201811L <iterator>
74+
__cpp_lib_constexpr_list 202502L <list>
7475
__cpp_lib_constexpr_memory 202202L <memory>
7576
201811L // C++20
7677
__cpp_lib_constexpr_new 202406L <new>
@@ -545,6 +546,7 @@ __cpp_lib_void_t 201411L <type_traits>
545546
# undef __cpp_lib_constexpr_algorithms
546547
# define __cpp_lib_constexpr_algorithms 202306L
547548
# define __cpp_lib_constexpr_forward_list 202502L
549+
# define __cpp_lib_constexpr_list 202502L
548550
# if !defined(_LIBCPP_ABI_VCRUNTIME)
549551
# define __cpp_lib_constexpr_new 202406L
550552
# endif

libcxx/test/std/containers/sequences/list/compare.pass.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@
1010

1111
// template< class T, class Alloc >
1212
// bool operator==( const std::list<T,Alloc>& lhs,
13-
// const std::list<T,Alloc>& rhs );
13+
// const std::list<T,Alloc>& rhs ); // constexpr since C++26
1414

1515
// template< class T, class Alloc >
1616
// bool operator!=( const std::list<T,Alloc>& lhs,
17-
// const std::list<T,Alloc>& rhs );
17+
// const std::list<T,Alloc>& rhs ); // constexpr since C++26
1818

1919
// template< class T, class Alloc >
2020
// bool operator<( const std::list<T,Alloc>& lhs,
21-
// const std::list<T,Alloc>& rhs );
21+
// const std::list<T,Alloc>& rhs ); // constexpr since C++26
2222

2323
// template< class T, class Alloc >
2424
// bool operator<=( const std::list<T,Alloc>& lhs,
25-
// const std::list<T,Alloc>& rhs );
25+
// const std::list<T,Alloc>& rhs ); // constexpr since C++26
2626

2727
// template< class T, class Alloc >
2828
// bool operator>( const std::list<T,Alloc>& lhs,
29-
// const std::list<T,Alloc>& rhs );
29+
// const std::list<T,Alloc>& rhs ); // constexpr since C++26
3030

3131
// template< class T, class Alloc >
3232
// bool operator>=( const std::list<T,Alloc>& lhs,
33-
// const std::list<T,Alloc>& rhs );
33+
// const std::list<T,Alloc>& rhs ); // constexpr since C++26
3434

3535
#include <list>
3636
#include <cassert>
3737

3838
#include "test_comparisons.h"
3939

40-
int main(int, char**) {
40+
TEST_CONSTEXPR_CXX26 bool test() {
4141
{
4242
const std::list<int> l1, l2;
4343
assert(testComparisons(l1, l2, true, false));
@@ -113,5 +113,15 @@ int main(int, char**) {
113113
const std::list<LessAndEqComp> l2(items2, items2 + 2);
114114
assert(testComparisons(l1, l2, false, false));
115115
}
116+
117+
return true;
118+
}
119+
120+
int main(int, char**) {
121+
assert(test());
122+
#if TEST_STD_VER >= 26
123+
static_assert(test());
124+
#endif
125+
116126
return 0;
117127
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

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

1616
#include <list>
1717
#include <cassert>
@@ -20,6 +20,8 @@
2020

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

libcxx/test/std/containers/sequences/list/get_allocator.pass.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
// class list
1212

13-
// allocator_type get_allocator() const
13+
// allocator_type get_allocator() const // constexpr since C++26
1414

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

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

21-
int main(int, char**) {
21+
TEST_CONSTEXPR_CXX26 bool test() {
2222
{
2323
std::allocator<int> alloc;
2424
const std::list<int> l(alloc);
@@ -30,5 +30,14 @@ int main(int, char**) {
3030
assert(l.get_allocator() == alloc);
3131
}
3232

33+
return true;
34+
}
35+
36+
int main(int, char**) {
37+
assert(test());
38+
#if TEST_STD_VER >= 26
39+
static_assert(test());
40+
#endif
41+
3342
return 0;
3443
}

libcxx/test/std/containers/sequences/list/incomplete_type.pass.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// type.
1313

1414
#include <list>
15+
#include <cassert>
1516

1617
#include "test_macros.h"
1718

@@ -23,8 +24,18 @@ struct A {
2324
std::list<A>::const_reverse_iterator crit;
2425
};
2526

26-
int main(int, char**) {
27+
TEST_CONSTEXPR_CXX26 bool test() {
2728
A a;
29+
(void)a;
30+
31+
return true;
32+
}
33+
34+
int main(int, char**) {
35+
assert(test());
36+
#if TEST_STD_VER >= 26
37+
static_assert(test());
38+
#endif
2839

2940
return 0;
3041
}

libcxx/test/std/containers/sequences/list/iterators.pass.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
// <list>
1010

11-
// iterator begin();
12-
// iterator end();
13-
// const_iterator begin() const;
14-
// const_iterator end() const;
15-
// const_iterator cbegin() const;
16-
// const_iterator cend() const;
11+
// iterator begin(); // constexpr since C++26
12+
// iterator end(); // constexpr since C++26
13+
// const_iterator begin() const; // constexpr since C++26
14+
// const_iterator end() const; // constexpr since C++26
15+
// const_iterator cbegin() const; // constexpr since C++26
16+
// const_iterator cend() const; // constexpr since C++26
1717

1818
#include <list>
1919
#include <cassert>
@@ -27,7 +27,7 @@ struct A {
2727
int second;
2828
};
2929

30-
int main(int, char**) {
30+
TEST_CONSTEXPR_CXX26 bool test() {
3131
{
3232
typedef int T;
3333
typedef std::list<T> C;
@@ -74,6 +74,8 @@ int main(int, char**) {
7474
typedef std::list<T> C;
7575
C::iterator i;
7676
C::const_iterator j;
77+
(void)i;
78+
(void)j;
7779
}
7880
#if TEST_STD_VER >= 11
7981
{
@@ -122,6 +124,8 @@ int main(int, char**) {
122124
typedef std::list<T, min_allocator<T>> C;
123125
C::iterator i;
124126
C::const_iterator j;
127+
(void)i;
128+
(void)j;
125129
}
126130
{
127131
typedef A T;
@@ -150,5 +154,14 @@ int main(int, char**) {
150154
}
151155
#endif
152156

157+
return true;
158+
}
159+
160+
int main(int, char**) {
161+
assert(test());
162+
#if TEST_STD_VER >= 26
163+
static_assert(test());
164+
#endif
165+
153166
return 0;
154167
}

libcxx/test/std/containers/sequences/list/list.capacity/empty.pass.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
// class list
1212

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

1515
#include <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::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/list/list.capacity/max_size.pass.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// <list>
1010

11-
// size_type max_size() const noexcept
11+
// size_type max_size() const noexcept // constexpr since C++26
1212

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

21-
int main(int, char**) {
21+
TEST_CONSTEXPR_CXX26 bool test() {
2222
{
2323
typedef limited_allocator<int, 10> A;
2424
typedef std::list<int, A> C;
@@ -42,5 +42,14 @@ int main(int, char**) {
4242
assert(c.max_size() <= alloc_max_size(c.get_allocator()));
4343
}
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/list/list.capacity/resize_size.pass.cpp

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88

99
// <list>
1010

11-
// void resize(size_type sz);
11+
// void resize(size_type sz); // constexpr since C++26
1212

1313
#include <list>
1414
#include <cassert>
15+
#include <type_traits>
16+
1517
#include "test_macros.h"
1618
#include "DefaultOnly.h"
1719
#include "min_allocator.h"
1820

19-
int main(int, char**) {
21+
TEST_CONSTEXPR_CXX26 bool test() {
2022
{
2123
std::list<int> l(5, 2);
2224
l.resize(2);
@@ -33,17 +35,31 @@ int main(int, char**) {
3335
assert(l.back() == 0);
3436
}
3537
#if TEST_STD_VER >= 11
36-
{
37-
std::list<DefaultOnly> l(10);
38-
l.resize(5);
39-
assert(l.size() == 5);
40-
assert(std::distance(l.begin(), l.end()) == 5);
41-
}
42-
{
43-
std::list<DefaultOnly> l(10);
44-
l.resize(20);
45-
assert(l.size() == 20);
46-
assert(std::distance(l.begin(), l.end()) == 20);
38+
if (!std::is_constant_evaluated()) {
39+
{
40+
std::list<DefaultOnly> l(10);
41+
l.resize(5);
42+
assert(l.size() == 5);
43+
assert(std::distance(l.begin(), l.end()) == 5);
44+
}
45+
{
46+
std::list<DefaultOnly> l(10);
47+
l.resize(20);
48+
assert(l.size() == 20);
49+
assert(std::distance(l.begin(), l.end()) == 20);
50+
}
51+
{
52+
std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10);
53+
l.resize(5);
54+
assert(l.size() == 5);
55+
assert(std::distance(l.begin(), l.end()) == 5);
56+
}
57+
{
58+
std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10);
59+
l.resize(20);
60+
assert(l.size() == 20);
61+
assert(std::distance(l.begin(), l.end()) == 20);
62+
}
4763
}
4864
{
4965
std::list<int, min_allocator<int>> l(5, 2);
@@ -60,18 +76,15 @@ int main(int, char**) {
6076
assert(l.front() == 2);
6177
assert(l.back() == 0);
6278
}
63-
{
64-
std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10);
65-
l.resize(5);
66-
assert(l.size() == 5);
67-
assert(std::distance(l.begin(), l.end()) == 5);
68-
}
69-
{
70-
std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10);
71-
l.resize(20);
72-
assert(l.size() == 20);
73-
assert(std::distance(l.begin(), l.end()) == 20);
74-
}
79+
#endif
80+
81+
return true;
82+
}
83+
84+
int main(int, char**) {
85+
assert(test());
86+
#if TEST_STD_VER >= 26
87+
static_assert(test());
7588
#endif
7689

7790
return 0;

0 commit comments

Comments
 (0)