From c601817de19d561322dacea8cdbb39e815d8b106 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 16 Nov 2021 14:43:51 +0100 Subject: QGeometryFactory: don't make op== virtual MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That's too clever, and it backfires with compilation errors in C++20 mode: qt3d/tests/auto/render/meshfunctors/tst_meshfunctors.cpp:129:29: error: ambiguous overload for ‘operator==’ (operand types are ‘MeshFunctorA’ and ‘MeshFunctorB’) 129 | QVERIFY(!(*functorA == *functorB)); | ~~~~~~~~~ ^~ ~~~~~~~~~ | | | | MeshFunctorA MeshFunctorB qt3d/tests/auto/render/meshfunctors/tst_meshfunctors.cpp:72:10: note: candidate: ‘virtual bool MeshFunctorB::operator==(const Qt3DCore::QGeometryFactory&) const’ (reversed) 72 | bool operator ==(const Qt3DCore::QGeometryFactory &other) const override | ^~~~~~~~ qt3d/tests/auto/render/meshfunctors/tst_meshfunctors.cpp:50:10: note: candidate: ‘virtual bool MeshFunctorA::operator==(const Qt3DCore::QGeometryFactory&) const’ 50 | bool operator ==(const Qt3DCore::QGeometryFactory &other) const override | ^~~~~~~~ Fix by providing a symmetric operator== for QGeometryFactory that delegates to a virtual equals() method. Change-Id: I23d29ad1b16075629132f2b4757c5810d5615a36 Reviewed-by: Edward Welbourne Reviewed-by: Paul Lemire (cherry picked from commit ec291f9974ba6d25148955a0b9e55b30c589a9be) Reviewed-by: Qt Cherry-pick Bot --- src/core/geometry/qgeometryfactory_p.h | 4 +++- src/render/geometry/qmesh.cpp | 2 +- src/render/geometry/qmesh_p.h | 2 +- tests/auto/render/meshfunctors/tst_meshfunctors.cpp | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/geometry/qgeometryfactory_p.h b/src/core/geometry/qgeometryfactory_p.h index 47f3a5281..97114d658 100644 --- a/src/core/geometry/qgeometryfactory_p.h +++ b/src/core/geometry/qgeometryfactory_p.h @@ -66,7 +66,9 @@ class Q_3DCORESHARED_EXPORT QGeometryFactory : public QAbstractFunctor public: virtual ~QGeometryFactory(); virtual QGeometry *operator()() = 0; - virtual bool operator ==(const QGeometryFactory &other) const = 0; + virtual bool equals(const QGeometryFactory &other) const = 0; + friend bool operator==(const QGeometryFactory &lhs, const QGeometryFactory &rhs) + { return lhs.equals(rhs); } }; typedef QSharedPointer QGeometryFactoryPtr; diff --git a/src/render/geometry/qmesh.cpp b/src/render/geometry/qmesh.cpp index 1180380b0..9bcad868d 100644 --- a/src/render/geometry/qmesh.cpp +++ b/src/render/geometry/qmesh.cpp @@ -388,7 +388,7 @@ Qt3DCore::QGeometry *MeshLoaderFunctor::operator()() /*! * \internal */ -bool MeshLoaderFunctor::operator ==(const QGeometryFactory &other) const +bool MeshLoaderFunctor::equals(const QGeometryFactory &other) const { const MeshLoaderFunctor *otherFunctor = functor_cast(&other); if (otherFunctor != nullptr) diff --git a/src/render/geometry/qmesh_p.h b/src/render/geometry/qmesh_p.h index 9d34a6ae6..e38f5779b 100644 --- a/src/render/geometry/qmesh_p.h +++ b/src/render/geometry/qmesh_p.h @@ -119,7 +119,7 @@ public : QMesh::Status status() const { return m_status; } Qt3DCore::QGeometry *operator()() override; - bool operator ==(const Qt3DCore::QGeometryFactory &other) const override; + bool equals(const Qt3DCore::QGeometryFactory &other) const override; QT3D_FUNCTOR(MeshLoaderFunctor) private: diff --git a/tests/auto/render/meshfunctors/tst_meshfunctors.cpp b/tests/auto/render/meshfunctors/tst_meshfunctors.cpp index fc22b17f7..bf8d9f2af 100644 --- a/tests/auto/render/meshfunctors/tst_meshfunctors.cpp +++ b/tests/auto/render/meshfunctors/tst_meshfunctors.cpp @@ -47,7 +47,7 @@ public: return nullptr; } - bool operator ==(const Qt3DCore::QGeometryFactory &other) const override + bool equals(const Qt3DCore::QGeometryFactory &other) const override { return Qt3DCore::functor_cast(&other); } @@ -69,7 +69,7 @@ public: return nullptr; } - bool operator ==(const Qt3DCore::QGeometryFactory &other) const override + bool equals(const Qt3DCore::QGeometryFactory &other) const override { return Qt3DCore::functor_cast(&other); } @@ -86,7 +86,7 @@ public: ~MeshFunctorASub() {} - bool operator ==(const Qt3DCore::QGeometryFactory &other) const override + bool equals(const Qt3DCore::QGeometryFactory &other) const override { return Qt3DCore::functor_cast(&other); } -- cgit v1.2.3