Unsolved error: C2057: expected constant expression
-
@kenchan No. I'm with same error... I solved the cl error before create this thread. Once this compiled, I got expected constant expression error.
-
@Dr.-No Oh dear :-(.
OK so just to clarify where you are now when you get this error...
which Qt are you now building against?
which version of Visual Studio are you now building with?
are you using the QT Creator IDE to build the project?
are you using Visual Studio IDE to build the project? -
@kenchan This is really bad, I have no idea why I'm getting this error. :( I'm downloading 5.10.1 to see if it works. Hope it's something has been fixed.
which Qt are you now building against?
Qt creator 4.2.0 and Qt 5.7.1
which version of Visual Studio are you now building with?
Visual studio community 2017
are you using the QT Creator IDE to build the project?
yes, as mentioned, version 4.2.0
are you using Visual Studio IDE to build the project?
nope... as it Qt project (written using mingw) I have only used Qt creator IDE.
-
@Dr.-No Thank you for clarifying that :-). Please post back here the results when using Qt 5.10.1.
I might have a Qt 5.7.1 around here somewhere :-) -
@kenchan on the "issues" window within Qt Creator IDE, the error is:
C:\Qt-MSVC\Qt5.7.1\5.7\msvc2015\include\QtCore\qmetatype.h:945: error: expected constant expression
looking in the compiler output window, I can see those erros too:
qmetatype.h:944: see reference to class template instantiation 'QtMetaTypePrivate::CapabilitiesImpl<QList<QVariant>,std::random_access_iterator_tag>' being compiled qmetatype.h:1015: see reference to class template instantiation 'QtMetaTypePrivate::ContainerAPI<T>' being compiled with [ T=QVariantList ] qvariant.h:711: see reference to function template instantiation 'QtMetaTypePrivate::QSequentialIterableImpl::QSequentialIterableImpl<QVariantList>(const T *)' being compiled with [ T=QVariantList ]
Soon as I try Qt 5.10.1 I'll post the results here.
EDIT
This is the line of error qmetatype.h:945:
{ enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };
from:
struct CapabilitiesImpl<T, std::random_access_iterator_tag> { enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };
-
@Dr.-No Hello again.
I had the same Qt package you have and hacked a kit to use the Vs 2017 compiler (v19.13.26129).
I built a simple widget project with a QMainWindow, did not see any issues.
I found this old bug report which looks relevant to the issue you saw.
I added the code to reproduce that in my test app but still did not see any issues when compiling...
Not sure what more I can do to help you with on that one :-(.
wishing you Good Luck with Qt 5.10.1 -
As I said this line is valid C++, it doesn't even require anything c++11 related.
I continue to believe that the error is cause by a misconfiguration of the IDE, which you should fix by configuring the kit (i.e. compiler and Qt distribution). Information is aplenty - reading the creator manual (sourced in previous post) and searching the forums here should be just enough. -
@kenchan So I was trying luck with Qt 5.10.1. With mingw32 it compiled fine (the project was originally written with mingw32). But with both MSVC2015 and MS2017 I got that error. I haven't change a single line in that source code. It's the exact same source code but with MSVC it give that error. I need to use that compiler because the debugging library I mentioned which only works with MSVC compiler.
-
@kshegunov I'm trying to find the source of misconfiguration which I also believe is the reason of the error. Without running the vcvarsall.bat bar, the compilation with MSVC fail to find the rc executable. All the compilers are properly detected by Qt Creator IDE but it fails to compile, for example, didn't find rc or cl executable. I don't know where check... if it's a PATH missing. I've removed VS2015 affraid of some conflict with VC2017 remove all but the Qt 5.10. And nothing Works.
-
Hi @Dr.-No
We had some requests with missing cl.exe here in the forum (you could search for them), and there is e.g. https://bugreports.qt.io/browse/QTCREATORBUG-17474 (but maybe more).
In short: QtCreator runs the vcvarsXX.bat also, but in some setups this takes very long and times out. There are also solutions out there which hardcode the paths in the bat file that are determined by registry calls otherwise. You could do this too, if you know what you are doing ;)
In any case, the compiler has to match the Qt version and the path to the compiler must be correct. I assume that there is something wrong in your setup, and maybe (most likely) hte error C2057 is just a result of that.
Regards
-
@Dr-No Did you ever solve your problem?
I get the exact same error using VS2015 and VS2017 with Qt 5.9.2.
Annoyingly my app builds on the Windows Subsystem for Linux (Ubuntu 16.04.2 LTS) using gcc 5.4.0 and clang 5.0.2 with ninja 1.5.1.
I'm using CMake 5.11.1 to generate the project files in all instances.
It falls over on Windows the moment I#include <QAction>
(which includes QVariant).1>qmetatype.h(944,1): error C2057: expected constant expression 1>qmetatype.h(942,1): error C2057: template<typename T> 1>qmetatype.h(943,1): error C2057: struct CapabilitiesImpl<T, std::random_access_iterator_tag> 1>qmetatype.h(944,1): error C2057: { enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; }; 1>qmetatype.h(944,1): error C2057: ^ 1>qmetatype.h(954): message : see reference to class template instantiation 'QtMetaTypePrivate::CapabilitiesImpl<QList<QVariant>,std::random_access_iterator_tag>' being compiled 1>qmetatype.h(954): message : { static int size(const QList<T> *t) { return t->size(); } }; 1>qmetatype.h(1025): message : see reference to class template instantiation 'QtMetaTypePrivate::ContainerAPI<T>' being compiled 1>qmetatype.h(1025): message : with 1>qmetatype.h(1025): message : [ 1>qmetatype.h(1025): message : T=QVariantList 1>qmetatype.h(1025): message : ] 1>qmetatype.h(1025): message : , _iteratorCapabilities(ContainerAPI<T>::IteratorCapabilities) 1>qvariant.h(726): message : see reference to function template instantiation 'QtMetaTypePrivate::QSequentialIterableImpl::QSequentialIterableImpl<QVariantList>(const T *)' being compiled 1>qvariant.h(726): message : with 1>qvariant.h(726): message : [ 1>qvariant.h(726): message : T=QVariantList 1>qvariant.h(726): message : ] 1>qvariant.h(726): message : return QSequentialIterable(QtMetaTypePrivate::QSequentialIterableImpl(reinterpret_cast<const QVariantList*>(v.constData())));
UPDATE (SOLVED)
I finally found and fixed the issue.
In the cpp file that was including QAction i had this:namespace { template<typename E, typename U = std::underlying_type_t<E>> inline U operator|(const E& e1, const E& e2) noexcept { return static_cast<U>(e1) | static_cast<U>(e2); } }
which was getting used by Visual Studio in the definition of
IteratorCapabilities
(mentioned above).
The quick fix was to make the operator a compile time constant expression (constexpr
) and then everything builds however I've went for SFINAE so the operator is only used for the types I specify. -
No, I have never sold that issue. I eneded up using other library and toolset to archive what I wanted. Glad you solved.