Skip to content

Commit 7d2ca37

Browse files
committed
tests: Work around gcc12 bug with c++20 edge cases
There are multiple tests that, with gcc 12, get an ambiguous overload error, with the basic problem being multiple inheritance paths. Somehow, c++20 requires that this work, and gcc 13 accepts the code. (clang 15 also rejects this code, and clang 16 is ok). Because the point is to test qgis, not compiler conformance, and because this overload pattern does not appear in the codebase (it would error if it did), downcast one side of the comparison to the base class to avoid the error. Analysis and fix suggestion are due to Even Rouault. credit to @gdt for original commit
1 parent a624b45 commit 7d2ca37

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

tests/src/core/geometry/testqgsgeometrycollection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ void TestQgsGeometryCollection::geometryCollection()
195195
QVERIFY( !( emptyCollection == c11 ) );
196196
QVERIFY( emptyCollection != c11 );
197197
QgsPoint notCollection;
198-
QVERIFY( !( emptyCollection == notCollection ) );
199-
QVERIFY( emptyCollection != notCollection );
198+
QVERIFY( !( *static_cast< QgsAbstractGeometry * >( &emptyCollection ) == notCollection ) );
199+
QVERIFY( *static_cast< QgsAbstractGeometry * >( &emptyCollection ) != notCollection );
200200
QgsMultiPoint mp;
201201
QgsMultiLineString ml;
202202
QVERIFY( mp != ml );

tests/src/core/geometry/testqgslinestring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,8 @@ void TestQgsLineString::equality()
953953
QVERIFY( ls6 != QgsCircularString() );
954954

955955
QgsPoint p1;
956-
QVERIFY( !( ls6 == p1 ) );
957-
QVERIFY( ls6 != p1 );
956+
QVERIFY( !( *static_cast< QgsAbstractGeometry * >( &ls6 ) == p1 ) );
957+
QVERIFY( *static_cast< QgsAbstractGeometry * >( &ls6 ) != p1 );
958958
QVERIFY( ls6 == ls6 );
959959
}
960960

tests/src/core/geometry/testqgspoint.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,17 @@ void TestQgsPoint::equality()
372372

373373
QVERIFY( QgsPoint( Qgis::WkbType::Point, 2 / 3.0, 1 / 3.0 ) != QgsPoint( Qgis::WkbType::PointZ, 2 / 3.0, 1 / 3.0 ) );
374374

375+
/*
376+
* gcc12 throws an "ambiguous overload" error when there are
377+
* multiple possible choices due to inheritance. Downcast pt1 to
378+
* reduce the search space. This problem does not occur in actual
379+
* code -- only in tests. Accept a workaround because the point is
380+
* to test the code, not verify that the compiler is pedantically
381+
* correct.
382+
*/
375383
QgsLineString ls;
376-
QVERIFY( pt1 != ls );
377-
QVERIFY( !( pt1 == ls ) );
384+
QVERIFY( *static_cast< QgsAbstractGeometry * >( &pt1 ) != ls );
385+
QVERIFY( !( *static_cast< QgsAbstractGeometry * >( &pt1 ) == ls ) );
378386
}
379387

380388
void TestQgsPoint::operators()

tests/src/core/geometry/testqgspolygon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ void TestQgsPolygon::equality()
267267
QVERIFY( !( pl1 != pl2 ) );
268268

269269
QgsLineString ls;
270-
QVERIFY( pl1 != ls );
271-
QVERIFY( !( pl1 == ls ) );
270+
QVERIFY( *static_cast< QgsAbstractGeometry * >( &pl1 ) != ls );
271+
QVERIFY( !( *static_cast< QgsAbstractGeometry * >( &pl1 ) == ls ) );
272272
}
273273

274274
void TestQgsPolygon::clone()

0 commit comments

Comments
 (0)