simulton / QSchematic

A library that allows creating diagrams such as flowcharts or even proper engineering schematics within a Qt application.
https://simulton.com
MIT License
231 stars 60 forks source link

Build failed under QT 6.6.0 on error: no match for ‘operator&&’ #46

Closed vowstar closed 10 months ago

vowstar commented 10 months ago

QT 6.6.0 has been released recently. The distribution version I am using, Gentoo, has been fully upgraded to 6.6.0. After the system upgrade, a compilation error was discovered.

[5/72] Building CXX object qschematic/CMakeFiles/qschematic-shared.dir/utils.cpp.o
FAILED: qschematic/CMakeFiles/qschematic-shared.dir/utils.cpp.o 
/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -Dqschematic_shared_EXPORTS -I/home/vowstar/Projects/2023/QSchematic/build/qschematic/qschematic-shared_autogen/include -I/home/vowstar/Projects/2023/QSchematic/qschematic -I/home/vowstar/Projects/2023/QSchematic/qschematic/.. -I/home/vowstar/Projects/2023/QSchematic/build/_deps/gpds-src/lib/include -isystem /usr/include/qt6/QtCore -isystem /usr/include/qt6 -isystem /usr/lib64/qt6/mkspecs/linux-g++ -isystem /usr/include/qt6/QtGui -isystem /usr/include/qt6/QtWidgets -fPIC -fPIC -MD -MT qschematic/CMakeFiles/qschematic-shared.dir/utils.cpp.o -MF qschematic/CMakeFiles/qschematic-shared.dir/utils.cpp.o.d -o qschematic/CMakeFiles/qschematic-shared.dir/utils.cpp.o -c /home/vowstar/Projects/2023/QSchematic/qschematic/utils.cpp
In file included from /usr/include/qt6/QtCore/qglobal.h:35,
                 from /usr/include/qt6/QtCore/qnamespace.h:12,
                 from /usr/include/qt6/QtCore/qpoint.h:7,
                 from /usr/include/qt6/QtCore/QPointF:1,
                 from /home/vowstar/Projects/2023/QSchematic/qschematic/wire_system/line.hpp:3,
                 from /home/vowstar/Projects/2023/QSchematic/qschematic/utils.cpp:1:
/home/vowstar/Projects/2023/QSchematic/qschematic/utils.cpp: In static member function ‘static QPointF QSchematic::Utils::clipPointToRectOutline(QPointF, const QRectF&)’:
/home/vowstar/Projects/2023/QSchematic/qschematic/utils.cpp:48:5: error: no match for ‘operator&&’ (operand types are ‘bool’ and ‘const QList<QLineF>::const_iterator’)
   48 |     Q_ASSERT(nearestEdge);
      |     ^~~~~~~~
/home/vowstar/Projects/2023/QSchematic/qschematic/utils.cpp:48:5: note: candidate: ‘operator&&(bool, bool)’ (built-in)
/home/vowstar/Projects/2023/QSchematic/qschematic/utils.cpp:48:5: note:   no known conversion for argument 2 from ‘const QList<QLineF>::const_iterator’ to ‘bool’
[6/72] Building CXX object qschematic/CMakeFiles/qschematic-static.dir/utils.cpp.o

The error message indicates that during compilation, Q_ASSERT cannot be used to check nearestEdge because nearestEdge is of type QVector<QLineF>::const_iterator, and Q_ASSERT requires its argument to be a boolean value.

The error occurs because Utils::lineClosestToPoint returns an iterator, not a direct QLineF object. The parameter for Q_ASSERT needs to be a boolean expression, so we need to check if nearestEdge is a valid iterator before using it.

The solution is to change the way Q_ASSERT is used, for example, we can change the code to:


Q_ASSERT(nearestEdge != edges.cend());

This ensures that nearestEdge is a valid iterator. If nearestEdge equals edges.cend(), it means that no nearest edge was found, and at this point, Q_ASSERT will trigger an assertion error.

Tectu commented 10 months ago

Good catch - Thank you!