diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-11-17 16:56:27 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2014-12-03 18:09:00 +0100 |
commit | cf475b91ae8dc3f6f72b70ca624533c42be34b9e (patch) | |
tree | ed27728e77a5b2077e095c3d2252d563dbd49252 /src/corelib/kernel/qmetatype.h | |
parent | d41834b953beb1a578cc1be8702dab9ac4a4c954 (diff) |
Implement proper C++ type numeric promotion for QVariant comparisons
Previously, QVariant would try to convert one operand to the other's
type, which would produce unexpected results: the results would depend
in the order of the operands and whether there was data loss in the
conversion. In addition, ordering comparisons were only done with signed
values, yielding other unexpected results, like
QVariant(LLONG_MAX / 2) < QVariant(Q_UINT64_C(0)).
Instead, try to obey the C++ standard rules for type promotion in
expressions. Our code is a little simpler than the standard would seem
to require since we know some more details from the ABI.
[ChangeLog][Important Behavior Changes][QVariant] QVariant now obeys the
C++ type promotion rules when comparing numeric types (integrals, float
and double), including the fact that unsigned comparisons are preferred
for types of the same rank (that is, now QVariant(-1) > QVariant(0U)).
Task-number: QTBUG-42722
Change-Id: Ie7b19073dcb45485354710975e561bcdb1a753f1
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Diffstat (limited to 'src/corelib/kernel/qmetatype.h')
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 1d8b9a8bdc..040b860a31 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -63,6 +63,7 @@ template <typename T> inline Q_DECL_CONSTEXPR int qMetaTypeId(); // F is a tuple: (QMetaType::TypeName, QMetaType::TypeNameID, RealType) +// ### Qt6: reorder the types to match the C++ integral type ranking #define QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)\ F(Void, 43, void) \ F(Bool, 1, bool) \ |