Skip to content

Commit 494c9e5

Browse files
mordantephilnik777
andauthored
[libc++] Removes basic_string::reserve(). (#73354)
Implements: - P2870R3 Remove basic_string::reserve() --------- Co-authored-by: philnik777 <[email protected]>
1 parent 84a2098 commit 494c9e5

File tree

8 files changed

+35
-6
lines changed

8 files changed

+35
-6
lines changed

libcxx/docs/ReleaseNotes/18.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Implemented Papers
5252
- P0020R6 - Floating Point Atomic
5353
- P2918R2 - Runtime format strings II
5454
- P2871R3 - Remove Deprecated Unicode Conversion Facets from C++26
55+
- P2870R3 - Remove basic_string::reserve()
5556

5657

5758
Improvements and New Features
@@ -75,6 +76,9 @@ Improvements and New Features
7576
- The ``_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT`` macro has been added to make
7677
the declarations in ``<codecvt>`` available.
7778

79+
- The ``_LIBCPP_ENABLE_CXX26_REMOVED_STRING_RESERVE`` macro has been added to make
80+
the function ``std::basic_string<...>::reserve()`` available.
81+
7882

7983
Deprecations and Removals
8084
-------------------------

libcxx/docs/Status/Cxx2cPapers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"`P2447R6 <https://wg21.link/P2447R6>`__","LWG","``std::span`` over an initializer list","Kona November 2023","","",""
3838
"`P2821R5 <https://wg21.link/P2821R5>`__","LWG","``span.at()``","Kona November 2023","","",""
3939
"`P2868R3 <https://wg21.link/P2868R3>`__","LWG","Remove Deprecated ``std::allocator`` Typedef From C++26","Kona November 2023","","",""
40-
"`P2870R3 <https://wg21.link/P2870R3>`__","LWG","Remove ``basic_string::reserve()`` From C++26","Kona November 2023","","",""
40+
"`P2870R3 <https://wg21.link/P2870R3>`__","LWG","Remove ``basic_string::reserve()`` From C++26","Kona November 2023","|Complete|","18.0",""
4141
"`P2871R3 <https://wg21.link/P2871R3>`__","LWG","Remove Deprecated Unicode Conversion Facets from C++26","Kona November 2023","|Complete|","18.0",""
4242
"`P2819R2 <https://wg21.link/P2819R2>`__","LWG","Add tuple protocol to complex","Kona November 2023","","",""
4343
"`P2937R0 <https://wg21.link/P2937R0>`__","LWG","Freestanding: Remove ``strtok``","Kona November 2023","","",""

libcxx/docs/UsingLibcxx.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ C++26 Specific Configuration Macros
335335
**_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT**:
336336
This macro is used to re-enable all named declarations in ``<codecvt>``.
337337

338+
**_LIBCPP_ENABLE_CXX26_REMOVED_STRING_RESERVE**
339+
This macro is used to re-enable the function
340+
``std::basic_string<...>::reserve()``.
338341

339342
Libc++ Extensions
340343
=================

libcxx/include/string

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public:
173173
constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23
174174
175175
void reserve(size_type res_arg); // constexpr since C++20
176-
void reserve(); // deprecated in C++20
176+
void reserve(); // deprecated in C++20, removed in C++26
177177
void shrink_to_fit(); // constexpr since C++20
178178
void clear() noexcept; // constexpr since C++20
179179
bool empty() const noexcept; // constexpr since C++20
@@ -1187,7 +1187,9 @@ public:
11871187

11881188
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __resize_default_init(size_type __n);
11891189

1190+
#if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRING_RESERVE)
11901191
_LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve() _NOEXCEPT { shrink_to_fit(); }
1192+
#endif
11911193
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
11921194
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT;
11931195

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// void reserve(); // Deprecated in C++20.
1212
// void reserve(size_type);
1313

14-
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
14+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_STRING_RESERVE
1515

1616
// This test ensures that libc++ implements https://wg21.link/P0966R1 (reserve never shrinks)
1717
// even before C++20. This is required in order to avoid ODR violations because basic_string::reserve(size)

libcxx/test/std/strings/basic.string/string.capacity/reserve.deprecated_in_cxx20.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// void reserve(); // Deprecated in C++20
1212

13-
// UNSUPPORTED: c++03, c++11, c++14, c++17
13+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++26
1414

1515
#include <string>
1616

libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp

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

99
// <string>
1010

11-
// void reserve(); // Deprecated in C++20.
11+
// void reserve(); // Deprecated in C++20, removed in C++26.
1212

13-
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
13+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_STRING_RESERVE
1414

1515
#include <string>
1616
#include <stdexcept>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
// <string>
10+
11+
// void reserve(); // Removed in C++26
12+
13+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
14+
15+
#include <string>
16+
17+
void f() {
18+
std::string s;
19+
s.reserve(); // expected-error {{too few arguments to function call}}
20+
}

0 commit comments

Comments
 (0)