mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
AK: Resolve clang-tidy warnings about unusual assignment operators
Either not returning *this, or in the case of Variant, not checking for self assignment. In AK::Atomic, we can't return *this due to the wrapper semantics Atomic implements.
This commit is contained in:
parent
22feb9d47b
commit
163367da39
Notes:
sideshowbarker
2024-07-18 01:08:05 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/163367da397 Pull-request: https://github.com/SerenityOS/serenity/pull/10737 Reviewed-by: https://github.com/BenWiederhake Reviewed-by: https://github.com/PeterBindels-TomTom Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/dascandy Reviewed-by: https://github.com/trflynn89
3 changed files with 17 additions and 9 deletions
|
@ -187,6 +187,7 @@ public:
|
|||
return *ret;
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-unconventional-assign-operator) We want operator= to exchange the value, so returning an object of type Atomic& here does not make sense
|
||||
ALWAYS_INLINE T operator=(T desired) volatile noexcept
|
||||
{
|
||||
store(desired);
|
||||
|
@ -317,6 +318,7 @@ public:
|
|||
return __atomic_load_n(&m_value, order);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-unconventional-assign-operator) We want operator= to exchange the value, so returning an object of type Atomic& here does not make sense
|
||||
ALWAYS_INLINE T operator=(T desired) volatile noexcept
|
||||
{
|
||||
store(desired);
|
||||
|
@ -417,6 +419,7 @@ public:
|
|||
return __atomic_load_n(&m_value, order);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-unconventional-assign-operator) We want operator= to exchange the value, so returning an object of type Atomic& here does not make sense
|
||||
T* operator=(T* desired) volatile noexcept
|
||||
{
|
||||
store(desired);
|
||||
|
|
|
@ -138,7 +138,8 @@ public:
|
|||
template<typename U>
|
||||
constexpr Checked& operator=(U value)
|
||||
{
|
||||
return *this = Checked(value);
|
||||
*this = Checked(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Checked& operator=(const Checked& other) = default;
|
||||
|
|
20
AK/Variant.h
20
AK/Variant.h
|
@ -271,11 +271,13 @@ public:
|
|||
requires(!(IsTriviallyCopyConstructible<Ts> && ...) || !(IsTriviallyDestructible<Ts> && ...))
|
||||
#endif
|
||||
{
|
||||
if constexpr (!(IsTriviallyDestructible<Ts> && ...)) {
|
||||
Helper::delete_(m_index, m_data);
|
||||
if (this != &other) {
|
||||
if constexpr (!(IsTriviallyDestructible<Ts> && ...)) {
|
||||
Helper::delete_(m_index, m_data);
|
||||
}
|
||||
m_index = other.m_index;
|
||||
Helper::copy_(other.m_index, other.m_data, m_data);
|
||||
}
|
||||
m_index = other.m_index;
|
||||
Helper::copy_(other.m_index, other.m_data, m_data);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -284,11 +286,13 @@ public:
|
|||
requires(!(IsTriviallyMoveConstructible<Ts> && ...) || !(IsTriviallyDestructible<Ts> && ...))
|
||||
#endif
|
||||
{
|
||||
if constexpr (!(IsTriviallyDestructible<Ts> && ...)) {
|
||||
Helper::delete_(m_index, m_data);
|
||||
if (this != &other) {
|
||||
if constexpr (!(IsTriviallyDestructible<Ts> && ...)) {
|
||||
Helper::delete_(m_index, m_data);
|
||||
}
|
||||
m_index = other.m_index;
|
||||
Helper::move_(other.m_index, other.m_data, m_data);
|
||||
}
|
||||
m_index = other.m_index;
|
||||
Helper::move_(other.m_index, other.m_data, m_data);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue