From 4f30a4426cdff363120a298b9db199089f7f37f8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 11 Sep 2024 16:03:47 -0700 Subject: [PATCH] QTypeRevision: fix support for 8-bit signed segments The logic in the isValidSegment() function was failing for 8-bit signed because for them Integer(SegmentUnknown) is -1, so (std::numeric_limits::max)() < Integer(SegmentUnknown) was always false (127 < -1) and the function would only return true on the impossible condition of segment >= 0 && segment < -1 Fixes: QTBUG-128848 Pick-to: 6.7 6.5 Change-Id: I8d17b93afd6c2982a099fffdcaeccf126b7a9d02 Reviewed-by: Ulf Hermann (cherry picked from commit ddfcc0734875cdee2c169bf2ecb1546bddba6e98) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qtyperevision.h | 6 ++++-- .../auto/corelib/tools/qtyperevision/tst_qtyperevision.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qtyperevision.h b/src/corelib/tools/qtyperevision.h index 8f255a77e89..c2b344f3400 100644 --- a/src/corelib/tools/qtyperevision.h +++ b/src/corelib/tools/qtyperevision.h @@ -45,9 +45,11 @@ public: static constexpr bool isValidSegment(Integer segment) { // using extra parentheses around max to avoid expanding it if it is a macro + // and adding zero to cause it to be promoted + constexpr auto Max = (std::numeric_limits::max)() + 0; + constexpr bool HasSufficientRange = Max >= SegmentUnknown; return segment >= Integer(0) - && ((std::numeric_limits::max)() < Integer(SegmentUnknown) - || segment < Integer(SegmentUnknown)); + && (!HasSufficientRange || segment < Integer(SegmentUnknown)); } template(); - // compileTestRevision(); + compileTestRevision(); compileTestRevision(); compileTestRevision(); compileTestRevision(); @@ -104,7 +104,7 @@ void tst_QTypeRevision::qTypeRevisionTypes() compileTestRevision(); compileTestRevision(); compileTestRevision(); - // compileTestRevision(); + compileTestRevision(); QVERIFY(!QTypeRevision::isValidSegment(0xff)); QVERIFY(!QTypeRevision::isValidSegment(-1));