Skip to content

Commit 656c5e3

Browse files
philnik777copybara-github
authored andcommitted
[libc++] Remove _LIBCPP_DISABLE_NODISCARD_EXTENSIONS and refactor the tests (#87094)
This also adds a few tests that were missing. NOKEYCHECK=True GitOrigin-RevId: 83bc7b57714dc2f6b33c188f2b95a0025468ba51
1 parent ada6120 commit 656c5e3

File tree

198 files changed

+1224
-1331
lines changed

Some content is hidden

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

198 files changed

+1224
-1331
lines changed

.clang-format

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ AttributeMacros: [
4444
'_LIBCPP_NO_SANITIZE',
4545
'_LIBCPP_NO_UNIQUE_ADDRESS',
4646
'_LIBCPP_NOALIAS',
47-
'_LIBCPP_NODISCARD_EXT',
4847
'_LIBCPP_NODISCARD',
4948
'_LIBCPP_NORETURN',
5049
'_LIBCPP_OVERRIDABLE_FUNC_VIS',

docs/ReleaseNotes/19.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ Deprecations and Removals
7979
in language modes prior to C++20. If you are using these features prior to C++20, please update to ``-std=c++20``.
8080
In LLVM 20, the C++20 synchronization library will be removed entirely in language modes prior to C++20.
8181

82+
- ``_LIBCPP_DISABLE_NODISCARD_EXT`` has been removed. ``[[nodiscard]]`` applications are now unconditional.
83+
This decision is based on LEWGs discussion on `P3122 <https://wg21.link/P3122>` and `P3162 <https://wg21.link/P3162>`
84+
to not use ``[[nodiscard]]`` in the standard.
85+
8286
- TODO: The ``LIBCXX_ENABLE_ASSERTIONS`` CMake variable that was used to enable the safe mode has been deprecated and setting
8387
it triggers an error; use the ``LIBCXX_HARDENING_MODE`` CMake variable with the value ``extensive`` instead. Similarly,
8488
the ``_LIBCPP_ENABLE_ASSERTIONS`` macro has been deprecated (setting it to ``1`` still enables the extensive mode in

docs/UsingLibcxx.rst

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ safety annotations.
196196
replacement scenarios from working, e.g. replacing `operator new` and
197197
expecting a non-replaced `operator new[]` to call the replaced `operator new`.
198198

199-
**_LIBCPP_DISABLE_NODISCARD_EXT**:
200-
This macro disables library-extensions of ``[[nodiscard]]``.
201-
See :ref:`Extended Applications of [[nodiscard]] <nodiscard extension>` for more information.
202-
203199
**_LIBCPP_DISABLE_DEPRECATION_WARNINGS**:
204200
This macro disables warnings when using deprecated components. For example,
205201
using `std::auto_ptr` when compiling in C++11 mode will normally trigger a
@@ -279,29 +275,6 @@ Libc++ Extensions
279275
This section documents various extensions provided by libc++, how they're
280276
provided, and any information regarding how to use them.
281277

282-
.. _nodiscard extension:
283-
284-
Extended applications of ``[[nodiscard]]``
285-
------------------------------------------
286-
287-
The ``[[nodiscard]]`` attribute is intended to help users find bugs where
288-
function return values are ignored when they shouldn't be. After C++17 the
289-
C++ standard has started to declared such library functions as ``[[nodiscard]]``.
290-
However, this application is limited and applies only to dialects after C++17.
291-
Users who want help diagnosing misuses of STL functions may desire a more
292-
liberal application of ``[[nodiscard]]``.
293-
294-
For this reason libc++ provides an extension that does just that! The
295-
extension is enabled by default and can be disabled by defining ``_LIBCPP_DISABLE_NODISCARD_EXT``.
296-
The extended applications of ``[[nodiscard]]`` takes two forms:
297-
298-
1. Backporting ``[[nodiscard]]`` to entities declared as such by the
299-
standard in newer dialects, but not in the present one.
300-
301-
2. Extended applications of ``[[nodiscard]]``, at the library's discretion,
302-
applied to entities never declared as such by the standard. You can find
303-
all such applications by grepping for ``_LIBCPP_NODISCARD_EXT``.
304-
305278
Extended integral type support
306279
------------------------------
307280

include/__algorithm/adjacent_find.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ _LIBCPP_PUSH_MACROS
2626
_LIBCPP_BEGIN_NAMESPACE_STD
2727

2828
template <class _Iter, class _Sent, class _BinaryPredicate>
29-
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
29+
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
3030
__adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
3131
if (__first == __last)
3232
return __first;
@@ -40,13 +40,13 @@ __adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
4040
}
4141

4242
template <class _ForwardIterator, class _BinaryPredicate>
43-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
43+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
4444
adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
4545
return std::__adjacent_find(std::move(__first), std::move(__last), __pred);
4646
}
4747

4848
template <class _ForwardIterator>
49-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
49+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
5050
adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {
5151
return std::adjacent_find(std::move(__first), std::move(__last), __equal_to());
5252
}

include/__algorithm/all_of.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
_LIBCPP_BEGIN_NAMESPACE_STD
2020

2121
template <class _InputIterator, class _Predicate>
22-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
22+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2323
all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
2424
for (; __first != __last; ++__first)
2525
if (!__pred(*__first))

include/__algorithm/any_of.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
_LIBCPP_BEGIN_NAMESPACE_STD
2020

2121
template <class _InputIterator, class _Predicate>
22-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
22+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2323
any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
2424
for (; __first != __last; ++__first)
2525
if (__pred(*__first))

include/__algorithm/binary_search.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
_LIBCPP_BEGIN_NAMESPACE_STD
2323

2424
template <class _ForwardIterator, class _Tp, class _Compare>
25-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
25+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2626
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
2727
__first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
2828
return __first != __last && !__comp(__value, *__first);
2929
}
3030

3131
template <class _ForwardIterator, class _Tp>
32-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
32+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
3333
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
3434
return std::binary_search(__first, __last, __value, __less<>());
3535
}

include/__algorithm/clamp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121

2222
#if _LIBCPP_STD_VER >= 17
2323
template <class _Tp, class _Compare>
24-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
24+
[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
2525
clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
2626
_LIBCPP_LIFETIMEBOUND const _Tp& __lo,
2727
_LIBCPP_LIFETIMEBOUND const _Tp& __hi,
@@ -31,7 +31,7 @@ clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
3131
}
3232

3333
template <class _Tp>
34-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
34+
[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
3535
clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
3636
_LIBCPP_LIFETIMEBOUND const _Tp& __lo,
3737
_LIBCPP_LIFETIMEBOUND const _Tp& __hi) {

include/__algorithm/count.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ __count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __l
7979
}
8080

8181
template <class _InputIterator, class _Tp>
82-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<_InputIterator>
82+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<_InputIterator>
8383
count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
8484
__identity __proj;
8585
return std::__count<_ClassicAlgPolicy>(__first, __last, __value, __proj);

include/__algorithm/count_if.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
_LIBCPP_BEGIN_NAMESPACE_STD
2121

2222
template <class _InputIterator, class _Predicate>
23-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
24-
typename iterator_traits<_InputIterator>::difference_type
25-
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
23+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
24+
typename iterator_traits<_InputIterator>::difference_type
25+
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
2626
typename iterator_traits<_InputIterator>::difference_type __r(0);
2727
for (; __first != __last; ++__first)
2828
if (__pred(*__first))

0 commit comments

Comments
 (0)