Skip to content

Commit 425620c

Browse files
committed
[libc++] Implement P0980R1 (constexpr std::string)
Reviewed By: #libc, ldionne Spies: daltenty, sdasgup3, ldionne, arichardson, MTC, ChuanqiXu, mehdi_amini, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, Kayjukh, jurahul, msifontes, tatianashp, rdzhabarov, teijeong, cota, dcaballe, Chia-hungDuan, wrengr, wenzhicui, arphaman, Mordante, miscco, Quuxplusone, smeenai, libcxx-commits Differential Revision: https://reviews.llvm.org/D110598
1 parent 6e078f9 commit 425620c

File tree

211 files changed

+2293
-2076
lines changed

Some content is hidden

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

211 files changed

+2293
-2076
lines changed

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Status
214214
------------------------------------------------- -----------------
215215
``__cpp_lib_constexpr_numeric`` ``201911L``
216216
------------------------------------------------- -----------------
217-
``__cpp_lib_constexpr_string`` ``201811L``
217+
``__cpp_lib_constexpr_string`` ``201907L``
218218
------------------------------------------------- -----------------
219219
``__cpp_lib_constexpr_string_view`` ``201811L``
220220
------------------------------------------------- -----------------

libcxx/docs/Status/Cxx20Papers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"`P0645R10 <https://wg21.link/P0645R10>`__","LWG","Text Formatting","Cologne","|Complete| [#note-P0645]_","14.0"
107107
"`P0660R10 <https://wg21.link/P0660R10>`__","LWG","Stop Token and Joining Thread, Rev 10","Cologne","",""
108108
"`P0784R7 <https://wg21.link/P0784R7>`__","CWG","More constexpr containers","Cologne","|Complete|","12.0"
109-
"`P0980R1 <https://wg21.link/P0980R1>`__","LWG","Making std::string constexpr","Cologne","",""
109+
"`P0980R1 <https://wg21.link/P0980R1>`__","LWG","Making std::string constexpr","Cologne","|Complete|","15.0"
110110
"`P1004R2 <https://wg21.link/P1004R2>`__","LWG","Making std::vector constexpr","Cologne","",""
111111
"`P1035R7 <https://wg21.link/P1035R7>`__","LWG","Input Range Adaptors","Cologne","",""
112112
"`P1065R2 <https://wg21.link/P1065R2>`__","LWG","Constexpr INVOKE","Cologne","|Complete|","12.0"

libcxx/include/string

Lines changed: 741 additions & 545 deletions
Large diffs are not rendered by default.

libcxx/include/version

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ __cpp_lib_constexpr_functional 201907L <functional>
6363
__cpp_lib_constexpr_iterator 201811L <iterator>
6464
__cpp_lib_constexpr_memory 201811L <memory>
6565
__cpp_lib_constexpr_numeric 201911L <numeric>
66-
__cpp_lib_constexpr_string 201811L <string>
66+
__cpp_lib_constexpr_string 201907L <string>
6767
__cpp_lib_constexpr_string_view 201811L <string_view>
6868
__cpp_lib_constexpr_tuple 201811L <tuple>
6969
__cpp_lib_constexpr_typeinfo 202106L <typeinfo>
@@ -316,7 +316,7 @@ __cpp_lib_void_t 201411L <type_traits>
316316
# define __cpp_lib_constexpr_iterator 201811L
317317
# define __cpp_lib_constexpr_memory 201811L
318318
# define __cpp_lib_constexpr_numeric 201911L
319-
# define __cpp_lib_constexpr_string 201811L
319+
# define __cpp_lib_constexpr_string 201907L
320320
# define __cpp_lib_constexpr_string_view 201811L
321321
# define __cpp_lib_constexpr_tuple 201811L
322322
# define __cpp_lib_constexpr_utility 201811L

libcxx/test/libcxx/strings/basic.string/string.capacity/max_size.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED:
10-
119
// <string>
1210

1311
// This test ensures that the correct max_size() is returned depending on the platform.

libcxx/test/std/language.support/support.limits/support.limits.general/string.version.compile.pass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/* Constant Value
1919
__cpp_lib_allocator_traits_is_always_equal 201411L [C++17]
2020
__cpp_lib_char8_t 201811L [C++20]
21-
__cpp_lib_constexpr_string 201811L [C++20]
21+
__cpp_lib_constexpr_string 201907L [C++20]
2222
__cpp_lib_erase_if 202002L [C++20]
2323
__cpp_lib_nonmember_container_access 201411L [C++17]
2424
__cpp_lib_ranges_to_container 202202L [C++2b]
@@ -211,8 +211,8 @@
211211
# ifndef __cpp_lib_constexpr_string
212212
# error "__cpp_lib_constexpr_string should be defined in c++20"
213213
# endif
214-
# if __cpp_lib_constexpr_string != 201811L
215-
# error "__cpp_lib_constexpr_string should have the value 201811L in c++20"
214+
# if __cpp_lib_constexpr_string != 201907L
215+
# error "__cpp_lib_constexpr_string should have the value 201907L in c++20"
216216
# endif
217217

218218
# ifndef __cpp_lib_erase_if
@@ -287,8 +287,8 @@
287287
# ifndef __cpp_lib_constexpr_string
288288
# error "__cpp_lib_constexpr_string should be defined in c++2b"
289289
# endif
290-
# if __cpp_lib_constexpr_string != 201811L
291-
# error "__cpp_lib_constexpr_string should have the value 201811L in c++2b"
290+
# if __cpp_lib_constexpr_string != 201907L
291+
# error "__cpp_lib_constexpr_string should have the value 201907L in c++2b"
292292
# endif
293293

294294
# ifndef __cpp_lib_erase_if

libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
__cpp_lib_constexpr_iterator 201811L [C++20]
6060
__cpp_lib_constexpr_memory 201811L [C++20]
6161
__cpp_lib_constexpr_numeric 201911L [C++20]
62-
__cpp_lib_constexpr_string 201811L [C++20]
62+
__cpp_lib_constexpr_string 201907L [C++20]
6363
__cpp_lib_constexpr_string_view 201811L [C++20]
6464
__cpp_lib_constexpr_tuple 201811L [C++20]
6565
__cpp_lib_constexpr_typeinfo 202106L [C++2b]
@@ -2725,8 +2725,8 @@
27252725
# ifndef __cpp_lib_constexpr_string
27262726
# error "__cpp_lib_constexpr_string should be defined in c++20"
27272727
# endif
2728-
# if __cpp_lib_constexpr_string != 201811L
2729-
# error "__cpp_lib_constexpr_string should have the value 201811L in c++20"
2728+
# if __cpp_lib_constexpr_string != 201907L
2729+
# error "__cpp_lib_constexpr_string should have the value 201907L in c++20"
27302730
# endif
27312731

27322732
# ifndef __cpp_lib_constexpr_string_view
@@ -3963,8 +3963,8 @@
39633963
# ifndef __cpp_lib_constexpr_string
39643964
# error "__cpp_lib_constexpr_string should be defined in c++2b"
39653965
# endif
3966-
# if __cpp_lib_constexpr_string != 201811L
3967-
# error "__cpp_lib_constexpr_string should have the value 201811L in c++2b"
3966+
# if __cpp_lib_constexpr_string != 201907L
3967+
# error "__cpp_lib_constexpr_string should have the value 201907L in c++2b"
39683968
# endif
39693969

39703970
# ifndef __cpp_lib_constexpr_string_view

libcxx/test/std/strings/basic.string/string.access/at.pass.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// XFAIL: LIBCXX-AIX-FIXME
10+
911
// <string>
1012

11-
// const_reference at(size_type pos) const;
12-
// reference at(size_type pos);
13+
// const_reference at(size_type pos) const; // constexpr since C++20
14+
// reference at(size_type pos); // constexpr since C++20
1315

1416
#include <string>
1517
#include <stdexcept>
@@ -30,7 +32,7 @@ test(S s, typename S::size_type pos)
3032
assert(cs.at(pos) == cs[pos]);
3133
}
3234
#ifndef TEST_HAS_NO_EXCEPTIONS
33-
else
35+
else if (!TEST_IS_CONSTANT_EVALUATED)
3436
{
3537
try
3638
{
@@ -54,7 +56,7 @@ test(S s, typename S::size_type pos)
5456
#endif
5557
}
5658

57-
bool test() {
59+
TEST_CONSTEXPR_CXX20 bool test() {
5860
{
5961
typedef std::string S;
6062
test(S(), 0);
@@ -81,7 +83,7 @@ int main(int, char**)
8183
{
8284
test();
8385
#if TEST_STD_VER > 17
84-
// static_assert(test());
86+
static_assert(test());
8587
#endif
8688

8789
return 0;

libcxx/test/std/strings/basic.string/string.access/back.pass.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// XFAIL: LIBCXX-AIX-FIXME
10+
911
// <string>
1012

11-
// const charT& back() const;
12-
// charT& back();
13+
// const charT& back() const; // constexpr since C++20
14+
// charT& back(); // constexpr since C++20
1315

1416
#include <string>
1517
#include <cassert>
@@ -32,7 +34,7 @@ test(S s)
3234
assert(s.back() == typename S::value_type('z'));
3335
}
3436

35-
bool test() {
37+
TEST_CONSTEXPR_CXX20 bool test() {
3638
{
3739
typedef std::string S;
3840
test(S("1"));
@@ -53,7 +55,7 @@ int main(int, char**)
5355
{
5456
test();
5557
#if TEST_STD_VER > 17
56-
// static_assert(test());
58+
static_assert(test());
5759
#endif
5860

5961
return 0;

libcxx/test/std/strings/basic.string/string.access/front.pass.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// XFAIL: LIBCXX-AIX-FIXME
10+
911
// <string>
1012

11-
// const charT& front() const;
12-
// charT& front();
13+
// const charT& front() const; // constexpr since C++20
14+
// charT& front(); // constexpr since C++20
1315

1416
#include <string>
1517
#include <cassert>
@@ -32,7 +34,7 @@ test(S s)
3234
assert(s.front() == typename S::value_type('z'));
3335
}
3436

35-
bool test() {
37+
TEST_CONSTEXPR_CXX20 bool test() {
3638
{
3739
typedef std::string S;
3840
test(S("1"));
@@ -53,7 +55,7 @@ int main(int, char**)
5355
{
5456
test();
5557
#if TEST_STD_VER > 17
56-
// static_assert(test());
58+
static_assert(test());
5759
#endif
5860

5961
return 0;

0 commit comments

Comments
 (0)