Qt Creator displaying warnings related to C++98
-
I'm running Qt Creator 15.0.1 on Windows, and I'm getting warnings about incompatibilites with C++98. This is appearing as annotations in code editor.
I've added the following to the .pro file, but it didn't change any behavior
CONFIG -= c++98 CONFIG += c++11 CONFIG += c++17
How can I get the clang code model to ignore C++98 issues?
-
C Christian Ehrlicher moved this topic from General and Desktop
-
@GregB You are currently adding both
C++11
andC++17
- please choose one of them. If you use an older Qt and therefore qmake version, you might need to replaceC++17
withC++1z
Also, I doubt that
CONFIG -= c++98
has any meaning, see https://doc.qt.io/qt-6/qmake-variable-reference.html#config for known variables.If you still encounter problems, please share the code you are getting warnings with.
Regards
-
I changed the .pro file to only contain the
c++17
. The warnings that I'm getting are within Qt Creator, not from the build process. Some example warnings are below:M:\nidb\src\nidb\modulePipeline.cpp:300: warning: 'auto' type specifier is incompatible with C++98 M:\nidb\src\nidb\modulePipeline.cpp:300: warning: If initialization statements are incompatible with C++ standards before C++17 M:\nidb\src\nidb\modulePipeline.cpp:1377: warning: Initialization of initializer_list object is incompatible with C++98 M:\nidb\src\nidb\modulePipeline.cpp:1867: warning: 'auto' type specifier is incompatible with C++98 M:\nidb\src\nidb\modulePipeline.cpp:1867: warning: If initialization statements are incompatible with C++ standards before C++17 M:\nidb\src\nidb\modulePipeline.cpp:2188: warning: Universal character name referring to a control character is incompatible with C++98
-
Line 300
foreach (int sid, studyids) {
Line 1377
QStringList bidsflags = { "BIDS_SUBJECTDIR_UID", "BIDS_STUDYDIR_STUDYNUM" };
Line 1867
foreach (QString group, groups) {
I'm not sure that the code is invalid? This code builds without warnings or error. The only issue is the warnings within Qt Creator generated by clangd within the editor. I recently upgraded my computer and reinstalled Qt Creator, and that's when I started getting the warnings. I was using 15.0.1 before, and 15.0.1 now. I must have had a setting turned off on my previous computer related to clangd, but I don't know what the setting is.
-
@GregB Thanks. Looking at the
foreach
source code there is indeed a linefor (auto name = QtPrivate::qMakeForeachContainer(container); name.i != name.e; ++name.i)
which is valid C++11 and higher code.So I think for some reason the code model does not pick up the
C++17
specifier. Can you try a minimal "Hello World" style example?@JonB Be careful with such suggestions. Changing
foreach()
to range-based for requires a studies with diploma exam ;)Regards
-
@aha_1980 said in Qt Creator displaying warnings related to C++98:
@JonB Be careful with such suggestions. Changing foreach() to range-based for requires a studies with diploma exam ;)
If you say so! I only know that I use
for
instead offoreach
(at least in similar cases to what the OP shows above, anint
and aQString
and their lists) and never had any issues? -
@JonB: You think you don't have any issues before you read the post Goodbye Q_FOREACH! I mentioned.
Regards
-
Thanks for the comments. So I don't think there's anything wrong with the code itself. It seems to be a configuration with Qt Creator and clangd that is ignoring the c++17 specification in the .pro file.
I found a previous post about this issue, and how they fixed it: https://forum.qt.io/topic/109856/incompatible-with-c-98-warnings-since-qt-creater-update/3
But that post is 5 years old, and none of the options they used to fix the issue exist in in the current Qt Creator.