summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-03-24 12:11:04 +0100
committerQt Cherry-pick Bot <[email protected]>2025-04-18 17:41:13 +0000
commita99b78bf51c21465f59f6b7a0a4883c42dc8092f (patch)
treefbe378a0d1e22ccaa07f9a1af1e8e5ab1fcb9621
parentdd934d675a10a0b06ba14dabd492e096658780fb (diff)
qcompare.h: standardize on Coverity-friendly ctors
Coverity complained that the Qt::strong_ordering(std::strong_ordering) ctor may leave m_order uninitialized, which is true if you assume that 'stdorder' could be anything else but {less, greater, equal}, which, however, should not happen™. Standardize on the pattern that QPartialOrdering(Qt::partial_ordering) was using: init m_order to equivalent, and then check for the other possible states. I would have preferred adding 'else Q_UNREACHABLE()', but these are constexpr functions, so we'd need the GCC 8 protection, and then the else would have a body longer than one line, and I don't know whether violating the coding style and adding {} only on the else would fly with reviewers, so that's done in a follow-up. Amends several changes (this code has seen a lot of churn over time). Coverity-Id: 475148 Change-Id: I3d88cdaaffbdfb8720161470b5f89046a3a15088 Reviewed-by: Ivan Solovev <[email protected]> Reviewed-by: Thiago Macieira <[email protected]> (cherry picked from commit f6d878d5ce4d6e41c088698bd337cf7f4438433e) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit da619f9e0b855d1c4b72820ed304ae8229f76829)
-rw-r--r--src/corelib/global/qcompare.h14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/corelib/global/qcompare.h b/src/corelib/global/qcompare.h
index 9e1afe7527e..f2c87c0551c 100644
--- a/src/corelib/global/qcompare.h
+++ b/src/corelib/global/qcompare.h
@@ -143,11 +143,10 @@ public:
#ifdef __cpp_lib_three_way_comparison
constexpr Q_IMPLICIT partial_ordering(std::partial_ordering stdorder) noexcept
+ : m_order{} // == equivalent
{
if (stdorder == std::partial_ordering::less)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Less);
- else if (stdorder == std::partial_ordering::equivalent)
- m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Equivalent);
else if (stdorder == std::partial_ordering::greater)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Greater);
else if (stdorder == std::partial_ordering::unordered)
@@ -337,11 +336,10 @@ public:
#ifdef __cpp_lib_three_way_comparison
constexpr Q_IMPLICIT weak_ordering(std::weak_ordering stdorder) noexcept
+ : m_order{} // == equivalent
{
if (stdorder == std::weak_ordering::less)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Less);
- else if (stdorder == std::weak_ordering::equivalent)
- m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Equivalent);
else if (stdorder == std::weak_ordering::greater)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Greater);
}
@@ -533,13 +531,10 @@ public:
#ifdef __cpp_lib_three_way_comparison
constexpr Q_IMPLICIT strong_ordering(std::strong_ordering stdorder) noexcept
+ : m_order{} // == equivalent
{
if (stdorder == std::strong_ordering::less)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Less);
- else if (stdorder == std::strong_ordering::equivalent)
- m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Equivalent);
- else if (stdorder == std::strong_ordering::equal)
- m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Equal);
else if (stdorder == std::strong_ordering::greater)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Greater);
}
@@ -802,11 +797,10 @@ public:
#ifdef __cpp_lib_three_way_comparison
constexpr Q_IMPLICIT QPartialOrdering(std::partial_ordering stdorder) noexcept
+ : m_order{} // == equivalent
{
if (stdorder == std::partial_ordering::less)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Less);
- else if (stdorder == std::partial_ordering::equivalent)
- m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Equivalent);
else if (stdorder == std::partial_ordering::greater)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Greater);
else if (stdorder == std::partial_ordering::unordered)