Skip to content

Commit ff03257

Browse files
committed
Addressed review comments
1 parent 207b44f commit ff03257

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

libcxx/include/__memory/shared_ptr.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,9 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI shared_ptr {
584584
}
585585

586586
#if _LIBCPP_STD_VER < 20 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE)
587-
_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI bool unique() const _NOEXCEPT { return use_count() == 1; }
587+
[[__nodiscard__]] _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI bool unique() const _NOEXCEPT {
588+
return use_count() == 1;
589+
}
588590
#endif
589591

590592
_LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return get() != nullptr; }
@@ -986,14 +988,12 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator>(const shared_ptr<_Tp>& __x, const sh
986988
}
987989

988990
template <class _Tp, class _Up>
989-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool
990-
operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT {
991+
inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT {
991992
return !(__y < __x);
992993
}
993994

994995
template <class _Tp, class _Up>
995-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool
996-
operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT {
996+
inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT {
997997
return !(__x < __y);
998998
}
999999

libcxx/include/__memory/unique_ptr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,7 @@ operator<=>(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {
675675
#endif
676676

677677
template <class _T1, class _D1>
678-
inline _LIBCPP_HIDE_FROM_ABI
679-
_LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT {
678+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT {
680679
return !__x;
681680
}
682681

libcxx/test/libcxx/utilities/smartptr/nodiscard.verify.cpp

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

9+
// UNSUPPORTED: c++03
10+
11+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE
12+
913
// <memory>
1014

1115
// Check that functions are marked [[nodiscard]]
@@ -44,19 +48,22 @@ void test() {
4448
sPtr.get(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
4549
*sPtr; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
4650
sPtr.use_count(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
51+
#if TEST_STD_VER <= 20
52+
sPtr.unique(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
53+
#endif
4754
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
4855
sPtr.owner_before(std::shared_ptr<int>());
4956
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
5057
sPtr.owner_before(std::weak_ptr<int>());
51-
#if TEST_STD_VER >= 17
58+
# if TEST_STD_VER >= 17
5259
sPtr[0]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
53-
#endif
60+
# endif
5461

5562
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
5663
std::allocate_shared<int>(std::allocator<int>(), 5);
5764
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
5865
std::make_shared<int>();
59-
#if TEST_STD_VER >= 20
66+
# if TEST_STD_VER >= 20
6067
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
6168
std::allocate_shared_for_overwrite<int>(std::allocator<int>());
6269
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -89,38 +96,30 @@ void test() {
8996
std::make_shared<int[]>(5, 82);
9097
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
9198
std::make_shared_for_overwrite<int[]>(5);
92-
#endif
99+
# endif
93100

94101
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
95102
std::static_pointer_cast<int[]>(sPtr);
96-
#if TEST_STD_VER >= 20
97103
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
98104
std::static_pointer_cast<int[]>(std::move(sPtr));
99-
#endif
100105
class Empty {};
101106
std::shared_ptr<Empty> dsPtr;
102107
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
103108
std::dynamic_pointer_cast<Empty>(dsPtr);
104-
#if TEST_STD_VER >= 20
105109
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
106110
std::dynamic_pointer_cast<Empty>(std::move(dsPtr));
107-
#endif
108111
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
109112
std::const_pointer_cast<int[]>(sPtr);
110-
#if TEST_STD_VER >= 20
111113
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
112114
std::const_pointer_cast<int[]>(std::move(sPtr));
113-
#endif
114115
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
115116
std::reinterpret_pointer_cast<int[]>(sPtr);
116-
#if TEST_STD_VER >= 20
117117
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
118118
std::reinterpret_pointer_cast<int[]>(std::move(sPtr));
119-
#endif
120-
#if !defined(TEST_HAS_NO_RTTI)
119+
# if !defined(TEST_HAS_NO_RTTI)
121120
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
122121
std::get_deleter<int[]>(sPtr);
123-
#endif
122+
# endif
124123
}
125124
{ // [util.smartptr.weak]
126125
std::weak_ptr<int> wPtr;
@@ -140,18 +139,18 @@ void test() {
140139

141140
es.shared_from_this(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
142141
ces.shared_from_this(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
143-
#if TEST_STD_VER >= 17
142+
# if TEST_STD_VER >= 17
144143
es.weak_from_this(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
145144
ces.weak_from_this(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
146-
#endif
145+
# endif
147146
}
148-
#if TEST_STD_VER >= 23
147+
# if TEST_STD_VER >= 23
149148
{ // [smartptr.adapt]
150149
std::unique_ptr<int> uPtr;
151150
// [inout.ptr]
152151
std::inout_ptr(uPtr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
153152
// [out.ptr]
154153
std::out_ptr(uPtr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
155154
}
156-
#endif
155+
# endif
157156
}

0 commit comments

Comments
 (0)