Skip to content

Commit 6d5f2ae

Browse files
committed
spam nodiscard and noexcept
1 parent b20cb6f commit 6d5f2ae

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

stl/inc/functional

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ union alignas(max_align_t) _Move_only_function_data {
12161216
char _Data; // For aliasing
12171217

12181218
template <class _Fn>
1219-
static constexpr size_t _Buf_offset() noexcept {
1219+
[[nodiscard]] static constexpr size_t _Buf_offset() noexcept {
12201220
if constexpr (alignof(_Fn) <= sizeof(_Impl)) {
12211221
return sizeof(_Impl); // Data immediately after impl
12221222
} else {
@@ -1225,34 +1225,35 @@ union alignas(max_align_t) _Move_only_function_data {
12251225
}
12261226

12271227
template <class _Fn>
1228-
static constexpr size_t _Buf_size() noexcept {
1228+
[[nodiscard]] static constexpr size_t _Buf_size() noexcept {
12291229
return sizeof(_Pointers) - _Buf_offset<_Fn>();
12301230
}
12311231

12321232
template <class _Fn>
1233-
constexpr void* _Buf_ptr() {
1233+
[[nodiscard]] constexpr void* _Buf_ptr() noexcept {
12341234
return &_Data + _Buf_offset<_Fn>();
12351235
}
12361236

12371237
template <class _Fn>
1238-
_Fn* _Small_fn_ptr() {
1238+
[[nodiscard]] _Fn* _Small_fn_ptr() noexcept {
12391239
return static_cast<_Fn*>(_Buf_ptr<_Fn>());
12401240
}
12411241

12421242
template <class _Fn>
1243-
_Fn* _Large_fn_ptr() {
1243+
[[nodiscard]] _Fn* _Large_fn_ptr() noexcept {
12441244
return static_cast<_Fn*>(_Pointers[1]);
12451245
}
12461246

1247-
void _Set_large_fn_ptr(void* _Value) {
1247+
void _Set_large_fn_ptr(void* const _Value) noexcept {
12481248
_Pointers[1] = _Value;
12491249
}
12501250
};
12511251

12521252
template <class _Rx, class... Args>
12531253
struct _Move_only_function_impl { // per-callable-type structure acting as a virtual function table
1254-
// using vtable emulations gives more flexibility for optimizations and eliminates the need for RTTI
1255-
// (RTTI saving may be significant as with lambdas and binds there may be a lot of distinct callable types)
1254+
// using vtable emulations gives more flexibility for optimizations and reduces the need for RTTIs
1255+
// (RTTI saving may be significant as with lambdas and binds there may be a lot of distinct callable types,
1256+
// we don't have distinct wrapper class type for each callable type, only distinct functions when needed)
12561257

12571258
// Calls target
12581259
_Rx (*_Invoke)(_Move_only_function_data&, Args...);
@@ -1263,12 +1264,12 @@ struct _Move_only_function_impl { // per-callable-type structure acting as a vir
12631264
};
12641265

12651266
template <class _Rx, class... Args>
1266-
[[noreturn]] _Rx _Function_no_callable(_Move_only_function_data&, Args...) {
1267+
[[noreturn]] _Rx _Function_no_callable(_Move_only_function_data&, Args...) noexcept {
12671268
_CSTD abort(); // We are not std::function to throw bad_function_call
12681269
}
12691270

1270-
constexpr void _Function_noop_move(_Move_only_function_data&, _Move_only_function_data&) noexcept {}
1271-
constexpr void _Function_noop_destroy(_Move_only_function_data&) noexcept {}
1271+
inline void _Function_noop_move(_Move_only_function_data&, _Move_only_function_data&) noexcept {}
1272+
inline void _Function_noop_destroy(_Move_only_function_data&) noexcept {}
12721273

12731274
template <class _Rx, class... Args>
12741275
inline constexpr _Move_only_function_impl<_Rx, Args...> _Null_move_only_function = {
@@ -1278,12 +1279,12 @@ inline constexpr _Move_only_function_impl<_Rx, Args...> _Null_move_only_function
12781279
};
12791280

12801281
template <class _Fn, class _Rx, class... _Types>
1281-
_Rx _Function_invoke_small(_Move_only_function_data& _Self, _Types... _Args) {
1282+
[[nodiscard]] _Rx _Function_invoke_small(_Move_only_function_data& _Self, _Types... _Args) {
12821283
return (*_Self._Small_fn_ptr<_Fn>()) (_STD forward<_Types>(_Args)...);
12831284
}
12841285

12851286
template <class _Fn, class _Rx, class... _Types>
1286-
_Rx _Function_invoke_large(_Move_only_function_data& _Self, _Types... _Args) {
1287+
[[nodiscard]] _Rx _Function_invoke_large(_Move_only_function_data& _Self, _Types... _Args) {
12871288
return (*_Self._Large_fn_ptr<_Fn>()) (_STD forward<_Types>(_Args)...);
12881289
}
12891290

@@ -1328,7 +1329,7 @@ void _Function_move_memcpy(_Move_only_function_data& _Self, _Move_only_function_
13281329
}
13291330

13301331
template <class _Fn>
1331-
void* _Function_new_large(_Fn&& _Callable) {
1332+
[[nodiscard]] void* _Function_new_large(_Fn&& _Callable) {
13321333
struct [[nodiscard]] _Guard_type {
13331334
void* _Ptr;
13341335

@@ -1347,7 +1348,7 @@ void* _Function_new_large(_Fn&& _Callable) {
13471348
if constexpr (alignof(_Fn) <= __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
13481349
_Guard._Ptr = ::operator new(sizeof(_Fn));
13491350
} else {
1350-
_Guard._Ptr = ::operator new(sizeof(_Fn), align_val_t{alignof(_Fn)});
1351+
_Guard._Ptr = ::operator new (sizeof(_Fn), align_val_t{alignof(_Fn)});
13511352
}
13521353
::new (_Guard._Ptr) _Fn(_STD move(_Callable));
13531354
return exchange(_Guard._Ptr, nullptr);
@@ -1384,12 +1385,12 @@ public:
13841385
_Get_impl()->_Destroy(_Data);
13851386
}
13861387

1387-
bool _Is_null() const noexcept {
1388+
[[nodiscard]] bool _Is_null() const noexcept {
13881389
return _Data._Impl == &_Null_move_only_function<_Rx, _Types...>;
13891390
}
13901391

13911392
template <class _Fn>
1392-
static constexpr bool _Large_function_engaged() noexcept {
1393+
[[nodiscard]] static constexpr bool _Large_function_engaged() noexcept {
13931394
return sizeof(_Fn) > _Move_only_function_data::_Buf_size<_Fn>()
13941395
|| !is_nothrow_move_constructible_v<_Fn> || alignof(_Fn) > alignof(max_align_t);
13951396
}
@@ -1398,12 +1399,12 @@ public:
13981399
return size_t{_Size + sizeof(void*) - 1} & ~size_t{sizeof(void*) - 1};
13991400
}
14001401

1401-
const _Impl_t* _Get_impl() const noexcept {
1402+
[[nodiscard]] const _Impl_t* _Get_impl() const noexcept {
14021403
return static_cast<const _Impl_t*>(_Data._Impl);
14031404
}
14041405

14051406
template <class _Fn>
1406-
static constexpr _Impl_t _Create_impl() noexcept {
1407+
[[nodiscard]] static constexpr _Impl_t _Create_impl() noexcept {
14071408
_Impl_t _Impl{};
14081409
if constexpr (_Large_function_engaged<_Fn>()) {
14091410
_Impl._Invoke = _Function_invoke_large<_Fn, _Rx, _Types...>;
@@ -1438,7 +1439,7 @@ public:
14381439
}
14391440

14401441
template <class _Fn>
1441-
static const _Impl_t* _Create_impl_ptr() noexcept {
1442+
[[nodiscard]] static const _Impl_t* _Create_impl_ptr() noexcept {
14421443
static constexpr _Impl_t _Impl = _Create_impl<_Fn>();
14431444
return &_Impl;
14441445
}
@@ -1493,13 +1494,13 @@ public:
14931494
this->_Construct_with_fn(_STD forward<_Fn>(_Callable));
14941495
}
14951496

1496-
explicit operator bool() const noexcept {
1497+
[[nodiscard]] explicit operator bool() const noexcept {
14971498
return !this->_Is_null();
14981499
}
14991500

15001501
using _Call::operator();
15011502

1502-
friend bool operator==(const move_only_function& _This, nullptr_t) noexcept {
1503+
[[nodiscard]] friend bool operator==(const move_only_function& _This, nullptr_t) noexcept {
15031504
return _This._Is_null();
15041505
}
15051506
};

0 commit comments

Comments
 (0)