qmetatype.h: error: constexpr variable 'len' must be initialized by a constant expression
-
I created a simple application using Qt 6.2.4 and
-std=gnu++17
. The same code that compiles and runs with Qt 5.15.2 now throws the following error throughout the compilation:include/QtCore/qmetatype.h:2167:23: error: constexpr variable 'len' must be initialized by a constant expression constexpr int len = QTypeNormalizer{ nullptr }.normalizeTypeFromSignature(begin, end); ^
The code itself:
#include <QtWidgets/QApplication> #include <QtWidgets/QPushButton> int main(int argc, char *argv[]) { QApplication a(argc, argv); QPushButton hello("Hello world!", 0); hello.resize(500, 60); hello.show(); return a.exec(); }
Any clue what could be going on ?
-
Hi and welcome to devnet,
Are you using CMake or qmake ?
If qmake, try with:
CONFIG += c++17
-
@SGaist I have tried to reproduce it manually using C++17 with no luck
clang++ -x c++ -isystem llvm/lib/clang/stable/include -isystem libgcc/include/c++/9.3.0 -isystem libgcc/include/c++/9.3.0/x86_64linux -isystem glibc/include -isystem kernel-headers/include -isystem mesa/include -isystem glu/include -isystem alsa-lib/include -fcoroutines-ts -isystem llvm/lib/clang/stable/include -isystem libgcc/include/c++/9.3.0 -isystem libgcc/include/c++/9.3.0/x86_64linux -isystem glibc/include -isystem kernel-headers/include -isystem mesa/include -isystem glu/include -isystem alsa-lib/include -nostdinc -nostdinc++ -nostdlib -Wall -Werror -Wextra -Wvla -Wimplicit-fallthrough -Winconsistent-missing-destructor-override -Winconsistent-missing-override -Wnon-virtual-dtor -Wpedantic -pedantic -Wshadow -Wthread-safety -Wtype-limits -Wundef -Wunreachable-code -Wno-global-constructors -Wno-missing-field-initializers -Wno-sign-conversion -Wno-sign-compare -Wno-unused-parameter -Wno-format-pedantic -Wno-gnu-statement-expression -Wno-gnu-zero-variadic-macro-arguments -Wno-c11-extensions -Wno-c99-extensions -Wno-gnu-anonymous-struct -Wno-nullability-extension -Wno-nullability-completeness -Wno-language-extension-token -Wno-overlength-strings -Wno-c++17-extensions '-Wno-error=deprecated-declarations' -mavx2 -mbmi2 -mlzcnt -mpclmul -mfma -mf16c -fstack-protector -fPIC '--sysroot=hopefully_inexistent_dirname' -fsized-deallocation -Og -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer '-std=c++17' -B/tools/binutils/bin -fasynchronous-unwind-tables -fPIC -fPIC -I qt/Samples/SampleBundle/SampleBundle#default,private-headers.hmap -I qt/Samples/SampleBundle -I build-out -I qt/Samples/SampleBundle/SampleBundle -isystem qt/QtConcurrent -isystem qt/6.2.4/linux_x64/include -isystem qt/6.2.4/linux_x64/include/QtConcurrent -isystem qt/QtCore -isystem qt/6.2.4/linux_x64/include/QtCore -isystem qt/QtDBus -isystem qt/6.2.4/linux_x64/include/QtDBus -isystem qt/QtGui -isystem qt/6.2.4/linux_x64/include/QtGui -isystem qt/QtNetwork -isystem qt/6.2.4/linux_x64/include/QtNetwork -isystem qt/QtOpenGL -isystem qt/6.2.4/linux_x64/include/QtOpenGL -isystem qt/QtQml -isystem qt/6.2.4/linux_x64/include/QtQml -isystem qt/QtQmlModels -isystem qt/6.2.4/linux_x64/include/QtQmlModels -isystem qt/QtQmlWorkerScript -isystem qt/6.2.4/linux_x64/include/QtQmlWorkerScript -isystem qt/QtQuick -isystem qt/6.2.4/linux_x64/include/QtQuick -isystem qt/QtQuickControls2 -isystem qt/6.2.4/linux_x64/include/QtQuickControls2 -isystem qt/QtQuickShapes -isystem qt/6.2.4/linux_x64/include/QtQuickShapes -isystem qt/QtQuickTemplates2 -isystem qt/6.2.4/linux_x64/include/QtQuickTemplates2 -isystem qt/QtQuickWidgets -isystem qt/6.2.4/linux_x64/include/QtQuickWidgets -isystem qt/QtSvg -isystem qt/6.2.4/linux_x64/include/QtSvg -isystem qt/QtWebSockets -isystem qt/6.2.4/linux_x64/include/QtWebSockets -isystem qt/QtWidgets -isystem qt/6.2.4/linux_x64/include/QtWidgets -isystem qt/QtXcbQpa -Wno-shadow -Wno-deprecated -Wno-inconsistent-missing-destructor-override -Xclang -fdebug-compilation-dir -Xclang . -o qt/Samples/SampleBundle/SampleBundle#compile-moc_SampleApp.cpp.o091a2f2d,default/moc_SampleApp.cpp.o -c -H qt/Samples/SampleBundle/moc_SampleApp.cppSampleBundle/moc_SampleApp.cpp
I saw someone else posting about this issue when trying to upgrade from 5.14 to 6.2. It seems they never managed to get around the issue and stuck to Qt 5.14. I might end up going the same path and stick to Qt 5.15.2 as I have spent too much time on this
-
Something is a bit fishy here. You are setting gnu++17 in your project which IIRC is for gcc and you use clang in your test.
-
@bisoftmm , this might be an incompatibility with the many compiler options you set. To debug this further, can you try to strip down the command line to the bare minimum (i.e. leaving out all the -Wxyz , -Wno-xyz options)?
Is that compiler line by a build system?