From bde41bcb736c76664aae1138b28207f0f13c81ad Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 1 Feb 2023 10:43:29 +0100 Subject: [PATCH] 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 (cherry picked from commit 7b9f4aa0fc85e8c1950f0bdc2d3802f935e25f30) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qlocale_data_p.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/corelib/text/qlocale_data_p.h b/src/corelib/text/qlocale_data_p.h index bf6e37b09f5..e91c96e947e 100644 --- a/src/corelib/text/qlocale_data_p.h +++ b/src/corelib/text/qlocale_data_p.h @@ -45,8 +45,9 @@ struct alignas(uint32_t) AlphaCode { char code[4]; bool isValid() const noexcept { return asU32() != 0; } - bool operator==(AlphaCode other) const noexcept { return asU32() == other.asU32(); } private: + friend bool operator==(AlphaCode lhs, AlphaCode rhs) noexcept + { return lhs.asU32() == rhs.asU32(); } uint32_t asU32() const noexcept { return qFromUnaligned(code); } };