tst_QString: extend arg() tests with enums w/o explicit underlying_type

The QtDeclarative code causing QTBUG-131906 hits UB, because it tries
to store -666 in an enum {A, B}, which has a valid range of [0,1],
therefore its underlying_type is uint, yet, as per [conv.prom]/3¹,
integer-promotes to _int_ instead, so in Qt 6.8 would cause the
arg(int) overload to be called, outputting -666, while in Qt 6.9, it's
treated (correctly) as an unsigned value, outputting -666's two's
complement, a positive value.

Add a version of the scenario that does not cause UB.

¹ Thanks to Ahmad Samir for digging up the pertinent legalese.

Task-number: QTBUG-131906
Pick-to: 6.9 6.8 6.5
Change-Id: Iba1a04de523a0b4cd1c87deea40c643cf16df14f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Marc Mutz 2024-12-05 11:39:53 +01:00
parent a38cebfe23
commit e64fd05fec

View File

@ -6695,6 +6695,11 @@ void tst_QString::arg()
QLatin1String("[9223372036854775808]") );
// (unscoped) enums
enum Enum {
Foo1, Foo2, // reproducer for QTBUG-131906,
RangeExtended = -667, // but w/o the UB of out-of-range values
};
QCOMPARE(s4.arg(Enum(-666)), QLatin1String("[-666]"));
enum : int { FooS = -1 };
enum : uint { FooU = 1 };
QCOMPARE(s4.arg(FooS), QLatin1String("[-1]"));