Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preprocessor division by zero while evaluating `QT_CONFIG(printer)`

Tags:

c++

macros

qt5.9

Compiling with g++ (from Makefile generated with qmake) using the line

#if !QT_CONFIG(printer)
    // do something
#endif

gives a preprocessor error on both g++ (7.3.0)

test.cpp:25:6: error: division by zero in #if
 #if !QT_CONFIG(printer)

and clang (6.00)

test.cpp:25:6: error: division by zero in preprocessor expression
#if !QT_CONFIG(printer)
     ^~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:84:30: note: expanded from macro 'QT_CONFIG'
#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
                            ~^~~~~~~~~~~~~~~~~~~~~
1 error generated.

where clang++ gives the more detailed output. printer is not enabled, thus the macro as recommended to do conditional compilation. The QT version is 5.9.5. Any suggestions (wrong usage?) appreciated.

like image 285
pba Avatar asked Oct 19 '25 05:10

pba


2 Answers

This is fixed in Qt 5.12.3. The newer version of notepad.cpp begins:

#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QMessageBox>
#if defined(QT_PRINTSUPPORT_LIB)
#include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printer)
#if QT_CONFIG(printdialog)
#include <QPrintDialog>
#endif // QT_CONFIG(printdialog)
#include <QPrinter>   
#endif // QT_CONFIG(printer)
#endif // QT_PRINTSUPPORT_LIB
#include <QFont>
#include <QFontDialog>
like image 124
user11545776 Avatar answered Oct 21 '25 12:10

user11545776


I don't think you should focus on that macro. The point of that macro is to simply crash your compilation code when QT_FEATURE_printer is zero. The code was not designed to work otherwise.

Instead of using the macro conditionally try to find out why QT_FEATURE_printer is zero and include / configure dependencies to change that (it seems to be definend in printsupport/qtprintsupport-config.h).

like image 25
cprogrammer Avatar answered Oct 21 '25 12:10

cprogrammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!