Skip to content

Commit da6d71e

Browse files
[libc++] Remove functions deprecated in C++17 and removed in C++20
Works towards P0619R4. - `std::uncaught_exception` was not previously deprecated. This patch deprecates it since C++17 as per N4259. `std::uncaught_exceptions` is used instead as libc++ unconditionally provides this function. - `std::get_temporary_buffer` is replaced with the internal version `__get_temporary_buffer`. - `std::return_temporary_buffer` is replaced with direct `__libcpp_deallocate_unsized` call. Escape hatches: - `_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION` restores `std::uncaught_exception`. - `_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER` restores `std::get_temporary_buffer` and `std::return_temporary_buffer`.
1 parent 3db5c1e commit da6d71e

File tree

21 files changed

+50
-43
lines changed

21 files changed

+50
-43
lines changed

libcxx/docs/Status/Cxx17.rst

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Paper Status
4040

4141
.. note::
4242

43+
.. [#note-N4259] N4259: ``std::uncaught_exception`` is deprecated since version 20.0.
4344
.. [#note-P0067] P0067: ``std::(to|from)_chars`` for integrals has been available since version 7.0. ``std::to_chars`` for ``float`` and ``double`` since version 14.0 ``std::to_chars`` for ``long double`` uses the implementation for ``double``.
4445
.. [#note-P0226] P0226: Progress is tracked `here <https://https://libcxx.llvm.org/Status/SpecialMath.html>`_.
4546
.. [#note-P0607] P0607: The parts of P0607 that are not done are the ``<regex>`` bits.

libcxx/docs/Status/Cxx17Papers.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"`N4169 <https://wg21.link/n4169>`__","LWG","A proposal to add invoke function template","Urbana","|Complete|","3.7"
55
"`N4190 <https://wg21.link/n4190>`__","LWG","Removing auto_ptr, random_shuffle(), And Old <functional> Stuff.","Urbana","|Complete|","15.0"
66
"`N4258 <https://wg21.link/n4258>`__","LWG","Cleaning-up noexcept in the Library.","Urbana","|In Progress|","3.7"
7-
"`N4259 <https://wg21.link/n4259>`__","CWG","Wording for std::uncaught_exceptions","Urbana","|Complete|","3.7"
7+
"`N4259 <https://wg21.link/n4259>`__","CWG","Wording for std::uncaught_exceptions","Urbana","|Complete| [#note-N4259]_","3.7"
88
"`N4277 <https://wg21.link/n4277>`__","LWG","TriviallyCopyable ``reference_wrapper``\ .","Urbana","|Complete|","3.2"
99
"`N4279 <https://wg21.link/n4279>`__","LWG","Improved insertion interface for unique-key maps.","Urbana","|Complete|","3.7"
1010
"`N4280 <https://wg21.link/n4280>`__","LWG","Non-member size() and more","Urbana","|Complete|","3.6"

libcxx/docs/Status/Cxx20.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Paper Status
4444
.. [#note-P0645] P0645: The paper is implemented but still marked as an incomplete feature
4545
(the feature-test macro is not set).
4646
.. [#note-P0966] P0966: It was previously erroneously marked as complete in version 8.0. See `bug 45368 <https://llvm.org/PR45368>`__.
47-
.. [#note-P0619] P0619: Only sections D.8, D.9, D.10 and D.13 are implemented. Sections D.4, D.7, D.11, and D.12 remain undone.
47+
.. [#note-P0619] P0619: Section D.4 remains undone.
4848
.. [#note-P0883.1] P0883: shared_ptr and floating-point changes weren't applied as they themselves aren't implemented yet.
4949
.. [#note-P0883.2] P0883: ``ATOMIC_FLAG_INIT`` was marked deprecated in version 14.0, but was undeprecated with the implementation of LWG3659 in version 15.0.
5050
.. [#note-P0660] P0660: The paper is implemented but the features are experimental and can be enabled via ``-fexperimental-library``.

libcxx/docs/UsingLibcxx.rst

+6
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ C++17 Specific Configuration Macros
215215

216216
C++20 Specific Configuration Macros
217217
-----------------------------------
218+
**_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION**:
219+
This macro is used to re-enable `uncaught_exception`.
220+
218221
**_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE**:
219222
This macro is used to re-enable the function
220223
``std::shared_ptr<...>::unique()``.
@@ -231,6 +234,9 @@ C++20 Specific Configuration Macros
231234
**_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR**:
232235
This macro is used to re-enable `raw_storage_iterator`.
233236

237+
**_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER**:
238+
This macro is used to re-enable `get_temporary_buffer` and `return_temporary_buffer`.
239+
234240
**_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS**:
235241
This macro is used to re-enable `is_literal_type`, `is_literal_type_v`,
236242
`result_of` and `result_of_t`.

libcxx/include/__algorithm/inplace_merge.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,7 @@ _LIBCPP_HIDE_FROM_ABI void __inplace_merge(
211211
difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle);
212212
difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last);
213213
difference_type __buf_size = std::min(__len1, __len2);
214-
// TODO: Remove the use of std::get_temporary_buffer
215-
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
216-
pair<value_type*, ptrdiff_t> __buf = std::get_temporary_buffer<value_type>(__buf_size);
217-
_LIBCPP_SUPPRESS_DEPRECATED_POP
214+
pair<value_type*, ptrdiff_t> __buf = std::__get_temporary_buffer<value_type>(__buf_size);
218215
unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first);
219216
return std::__inplace_merge<_AlgPolicy>(
220217
std::move(__first), std::move(__middle), std::move(__last), __comp, __len1, __len2, __buf.first, __buf.second);

libcxx/include/__algorithm/stable_partition.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Pred
135135
pair<value_type*, ptrdiff_t> __p(0, 0);
136136
unique_ptr<value_type, __return_temporary_buffer> __h;
137137
if (__len >= __alloc_limit) {
138-
// TODO: Remove the use of std::get_temporary_buffer
139-
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
140-
__p = std::get_temporary_buffer<value_type>(__len);
141-
_LIBCPP_SUPPRESS_DEPRECATED_POP
138+
__p = std::__get_temporary_buffer<value_type>(__len);
142139
__h.reset(__p.first);
143140
}
144141
return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
@@ -275,10 +272,7 @@ _LIBCPP_HIDE_FROM_ABI _BidirectionalIterator __stable_partition_impl(
275272
pair<value_type*, ptrdiff_t> __p(0, 0);
276273
unique_ptr<value_type, __return_temporary_buffer> __h;
277274
if (__len >= __alloc_limit) {
278-
// TODO: Remove the use of std::get_temporary_buffer
279-
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
280-
__p = std::get_temporary_buffer<value_type>(__len);
281-
_LIBCPP_SUPPRESS_DEPRECATED_POP
275+
__p = std::__get_temporary_buffer<value_type>(__len);
282276
__h.reset(__p.first);
283277
}
284278
return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(

libcxx/include/__algorithm/stable_sort.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,7 @@ __stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last,
244244
pair<value_type*, ptrdiff_t> __buf(0, 0);
245245
unique_ptr<value_type, __return_temporary_buffer> __h;
246246
if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value)) {
247-
// TODO: Remove the use of std::get_temporary_buffer
248-
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
249-
__buf = std::get_temporary_buffer<value_type>(__len);
250-
_LIBCPP_SUPPRESS_DEPRECATED_POP
247+
__buf = std::__get_temporary_buffer<value_type>(__len);
251248
__h.reset(__buf.first);
252249
}
253250

libcxx/include/__exception/operations.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ using terminate_handler = void (*)();
2929
_LIBCPP_EXPORTED_FROM_ABI terminate_handler set_terminate(terminate_handler) _NOEXCEPT;
3030
_LIBCPP_EXPORTED_FROM_ABI terminate_handler get_terminate() _NOEXCEPT;
3131

32-
_LIBCPP_EXPORTED_FROM_ABI bool uncaught_exception() _NOEXCEPT;
32+
#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION)
33+
_LIBCPP_EXPORTED_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 bool uncaught_exception() _NOEXCEPT;
34+
#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION)
3335
_LIBCPP_EXPORTED_FROM_ABI int uncaught_exceptions() _NOEXCEPT;
3436

3537
class _LIBCPP_EXPORTED_FROM_ABI exception_ptr;

libcxx/include/__memory/temporary_buffer.h

+18-10
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
_LIBCPP_BEGIN_NAMESPACE_STD
2323

2424
template <class _Tp>
25-
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17 pair<_Tp*, ptrdiff_t>
26-
get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT {
25+
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI pair<_Tp*, ptrdiff_t>
26+
__get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT {
2727
pair<_Tp*, ptrdiff_t> __r(0, 0);
2828
const ptrdiff_t __m =
2929
(~ptrdiff_t(0) ^ ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) / sizeof(_Tp);
@@ -56,20 +56,28 @@ get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT {
5656
return __r;
5757
}
5858

59-
template <class _Tp>
60-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {
61-
std::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
62-
}
63-
6459
struct __return_temporary_buffer {
65-
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
6660
template <class _Tp>
6761
_LIBCPP_HIDE_FROM_ABI void operator()(_Tp* __p) const {
68-
std::return_temporary_buffer(__p);
62+
std::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
6963
}
70-
_LIBCPP_SUPPRESS_DEPRECATED_POP
7164
};
7265

66+
#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER)
67+
68+
template <class _Tp>
69+
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17 pair<_Tp*, ptrdiff_t>
70+
get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT {
71+
return std::__get_temporary_buffer<_Tp>(__n);
72+
}
73+
74+
template <class _Tp>
75+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {
76+
std::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
77+
}
78+
79+
#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER)
80+
7381
_LIBCPP_END_NAMESPACE_STD
7482

7583
#endif // _LIBCPP___MEMORY_TEMPORARY_BUFFER_H

libcxx/include/__ostream/basic_ostream.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& _
152152

153153
template <class _CharT, class _Traits>
154154
basic_ostream<_CharT, _Traits>::sentry::~sentry() {
155-
if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) && !uncaught_exception()) {
155+
if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) && uncaught_exceptions() == 0) {
156156
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
157157
try {
158158
#endif // _LIBCPP_HAS_NO_EXCEPTIONS

libcxx/include/exception

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ terminate_handler set_terminate(terminate_handler f ) noexcept;
4747
terminate_handler get_terminate() noexcept;
4848
[[noreturn]] void terminate() noexcept;
4949
50-
bool uncaught_exception() noexcept;
50+
bool uncaught_exception() noexcept; // deprecated in C++17, removed in C++20
5151
int uncaught_exceptions() noexcept; // C++17
5252
5353
typedef unspecified exception_ptr;

libcxx/include/memory

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ public:
182182
raw_storage_iterator operator++(int);
183183
};
184184
185-
template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
186-
template <class T> void return_temporary_buffer(T* p) noexcept;
185+
template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept; // deprecated in C++17, removed in C++20
186+
template <class T> void return_temporary_buffer(T* p) noexcept; // deprecated in C++17, removed in C++20
187187
188188
template <class T> T* addressof(T& r) noexcept;
189189
template <class T> T* addressof(const T&& r) noexcept = delete;

libcxx/include/syncstream

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ private:
358358
// TODO Use a more generic buffer.
359359
// That buffer should be light with almost no additional headers. Then
360360
// it can be use here, the __retarget_buffer, and place that use
361-
// the now deprecated get_temporary_buffer
361+
// the now removed get_temporary_buffer
362362

363363
basic_string<_CharT, _Traits, _Allocator> __str_;
364364
bool __emit_on_sync_{false};

libcxx/modules/std/exception.inc

-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ export namespace std {
2121
using std::terminate;
2222
using std::terminate_handler;
2323
using std::throw_with_nested;
24-
using std::uncaught_exception;
2524
using std::uncaught_exceptions;
2625
} // namespace std

libcxx/src/exception.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#define _LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION
10+
#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS
11+
912
#include <exception>
1013
#include <new>
1114
#include <typeinfo>

libcxx/test/libcxx/diagnostics/memory.nodiscard.verify.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// check that <memory> functions are marked [[nodiscard]]
1212

13+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER
1314
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
1415

1516
// clang-format off

libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ test()
282282
assert(array[9] == P(0, 2));
283283
}
284284
#if TEST_STD_VER >= 11 && !defined(TEST_HAS_NO_EXCEPTIONS)
285-
// TODO: Re-enable this test once we're no longer using get_temporary_buffer().
285+
// TODO: Re-enable this test once we get recursive inlining fixed.
286286
// For now it trips up GCC due to the use of always_inline.
287287
#if 0
288288
{ // check that the algorithm still works when no memory is available

libcxx/test/std/language.support/support.exception/uncaught/uncaught_exception.pass.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
// UNSUPPORTED: no-exceptions
10+
11+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION
12+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
13+
1014
// test uncaught_exception
1115

1216
#include <exception>

libcxx/test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
// UNSUPPORTED: c++03
1010

11+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER
1112
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
1213

1314
// <memory>

libcxx/test/std/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
// <memory>
1010

11+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER
1112
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
1213

1314
// template <class T>

libcxx/utils/libcxx/test/modules.py

-7
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@
5252
"std::operator==",
5353
]
5454

55-
# TODO MODULES remove zombie names
56-
# https://libcxx.llvm.org/Status/Cxx20.html#note-p0619
57-
SkipDeclarations["memory"] = [
58-
"std::return_temporary_buffer",
59-
"std::get_temporary_buffer",
60-
]
61-
6255
# include/__type_traits/is_swappable.h
6356
SkipDeclarations["type_traits"] = [
6457
"std::swap",

0 commit comments

Comments
 (0)