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.5 Change-Id: Iba1a04de523a0b4cd1c87deea40c643cf16df14f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit e64fd05fecae291c9d7358d2e47d7170995af256) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 06a209384aff389af1b73cc77266f9b392219845)
This commit is contained in:
parent
5df319b9d1
commit
738a84115f
@ -6686,6 +6686,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]"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user