From 5a0e5521e4455e98f963d65319e87eb53a644610 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 28 Dec 2020 02:06:41 +0100 Subject: [PATCH] QVectorND: make some constructors explicit QVector2D has implicit conversions towards QVector3D/4D, and QVector3D has an implicit conversion towards QVector4D. Although in principle this is fine because it's not a data loss, it's still sketchy; for instance, it allows mixed operations to compile: vector2d + vector3d; vector4d - vector3d; vector3d * vector4d; // ! (Random observation: the conversion from QPoint(F) to QVectorND are actually already marked as explicit.) This is a leftover not done for Qt 6.0. I am not making these opt-out: having an implicit conversion here is outright *dangerous*, and any usage that fails to compile needs to be inspected to make sure it was the intended behavior. [ChangeLog][Potentially Source-Incompatible Changes] The QVector2D/3D/4D converting constructors from another QVectorND now explicit. This was done to prevent a category of bugs resulting from operations accidentally mixing QVectorND objects. Fixes: QTBUG-90327 Change-Id: Ifcd873f6a0d3fc10b9e68c935fe1f69f86a2340b Reviewed-by: Volker Hilsheimer Reviewed-by: Edward Welbourne Reviewed-by: Lars Knoll --- src/gui/math3d/qvectornd.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/math3d/qvectornd.h b/src/gui/math3d/qvectornd.h index f39b164549e..48031105cfa 100644 --- a/src/gui/math3d/qvectornd.h +++ b/src/gui/math3d/qvectornd.h @@ -196,7 +196,7 @@ public: constexpr explicit QVector3D(QPoint point) noexcept; constexpr explicit QVector3D(QPointF point) noexcept; #ifndef QT_NO_VECTOR2D - constexpr QVector3D(QVector2D vector) noexcept; + constexpr explicit QVector3D(QVector2D vector) noexcept; constexpr QVector3D(QVector2D vector, float zpos) noexcept; #endif #ifndef QT_NO_VECTOR4D @@ -340,11 +340,11 @@ public: constexpr explicit QVector4D(QPoint point) noexcept; constexpr explicit QVector4D(QPointF point) noexcept; #ifndef QT_NO_VECTOR2D - constexpr QVector4D(QVector2D vector) noexcept; + constexpr explicit QVector4D(QVector2D vector) noexcept; constexpr QVector4D(QVector2D vector, float zpos, float wpos) noexcept; #endif #ifndef QT_NO_VECTOR3D - constexpr QVector4D(QVector3D vector) noexcept; + constexpr explicit QVector4D(QVector3D vector) noexcept; constexpr QVector4D(QVector3D vector, float wpos) noexcept; #endif