QLocaleData: fix AlphaCode::op== for C++20

The old function,

   bool AlphaCode::operator==(AlphaCode code) const noexcept

is not symmetric: the LHS argument is passed by cref and the RHS one
by (non-const) value. I didn't test, but this asymmetry might actually
make the operator ambiguous with its reversed version in C++20.

Fix by making a hidden friend. Even if it doesn't fix anything, hidden
friend relational operators are still where we want our code base to
migrate to, eventually (QTBUG-87973).

Change-Id: Icb74c24802a3fe6c2987c1db86880c0d72a7abdf
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 7b9f4aa0fc85e8c1950f0bdc2d3802f935e25f30)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-02-01 10:43:29 +01:00 committed by Qt Cherry-pick Bot
parent 05d6e3c876
commit bde41bcb73

View File

@ -45,8 +45,9 @@ struct alignas(uint32_t) AlphaCode {
char code[4]; char code[4];
bool isValid() const noexcept { return asU32() != 0; } bool isValid() const noexcept { return asU32() != 0; }
bool operator==(AlphaCode other) const noexcept { return asU32() == other.asU32(); }
private: private:
friend bool operator==(AlphaCode lhs, AlphaCode rhs) noexcept
{ return lhs.asU32() == rhs.asU32(); }
uint32_t asU32() const noexcept { return qFromUnaligned<uint32_t>(code); } uint32_t asU32() const noexcept { return qFromUnaligned<uint32_t>(code); }
}; };