There is code
#include <array>
struct Foo {
int bar;
};
int main() {
constexpr auto v = std::array{Foo{}};
return 0;
}
While compile whith C++17:
fatal error C1001: Internal compiler error. ... (compiler file 'msc1.cpp', line 1591)
INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\bin\HostX86\x86\CL.exe'
But this - compiles
#include <array>
struct Foo {
int bar;
};
int main() {
constexpr std::array<Foo, 1> v{Foo{}};
return 0;
}
All optimizations are disabled as described here
Is this a compiler bug?
This looks like the same bug reported on developercommunity.visualstudio.com under Regression: c++ internal compiler error in 16.7.0 with /std:c++17 (compiler file 'msc1.cpp', line 1591). I suggest you upvote that bug report, and keep an eye on it for possible resolutions.
The issue was introduced in the 16.7.0 update, and is not fixed as of the latest 16.7.5. Interim workarounds are to revert to 16.6.5, or drop /std:c++17 and use /std:default or /std:c++14 instead.
While trying to debug an issue with an assert macro I came across this problem. Using __declspec(noinline) on a lambda function in a template class generates a syntax warning in Visual Studio 2017:
error C2760: syntax error: unexpected token '__declspec', expected '{'
This is the failing code:
template<class R>
class test
{
public:
void DoStuff()
{
[]() __declspec(noinline) { }; // syntax error
}
};
int WinMain(void)
{
return 0;
}
If I go to my project settings and switch my platform toolset from v141 (vs2017) to v140 (vs2015) in the general section of the project properties dialog the error goes away .
If I change the class to not be a template class it also compiles correctly:
class test
{
public:
void DoStuff()
{
[]() __declspec(noinline) { }; // compiles fine
}
};
int WinMain(void)
{
return 0;
}
I'm curious why this wouldn't succeed using the v141 platform toolset. Is there some other project setting that could be affecting this?
I was able to fix this by updating Visual Studio 2017 to the latest version (15.9.7). Previously I was running version 15.6.7. Thanks to everyone who looked in and commented! :)
It works in VC++ 2019, so may just be a regression in 2017?
Why does this simple c++ code snippet do not compile?
#include <algorithm>
#define SIZE (1000)
struct S {
int *vect;
};
int main() {
struct S* s = static_cast<struct S*>(malloc(sizeof(struct S)));
s->vect = static_cast<int*>(malloc(sizeof(int) * SIZE));
for(int i = 0; i < SIZE; i++) {
s->vect[i] = i;
}
std::sort(s->vect, s->vect + SIZE);
}
The compiler returns the following error related to the std::sort call
1>C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\algorithm(3138):
error : access violation
1> return (pair<_RanIt, _RanIt>(_Pfirst, _Plast));
1> ^
I'm using visual studio enterprise 2017 version 15.5.2 and the intel compiler 64 bit version 17.0.4.210 Build 20170411.
The code is successfully compiled using the default visual studio compiler.
Can't find out what I'm doing wrong.
I've found out that unfortunately visual studio update 15.5.x breaks Intel Compiler 2017 as can be seen in the intel forum where I asked this same question. Hope it will be useful to others too.
Trying to compile the following call to boost::fusion::invoke in boost-1.56 fails in Visual Studio 2013 but there is no error when compiling with Visual Studio 2012.
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/fusion/functional.hpp>
void Function( int & output )
{
output = 12;
}
int main( int, char ** )
{
boost::fusion::vector1< int > parameters;
boost::function< void( int & ) > function = &Function;
boost::fusion::invoke( function, parameters );
return 0;
}
The compiler output is:
boost\fusion\functional\invocation\invoke.hpp(205): error C2039: 'type' : is not a member of 'boost::result_of<Function (const int &)>'
with
[
Function=boost::function<void (int &)>
]
boost\fusion\functional\invocation\invoke.hpp(163) : see reference to class template instantiation 'boost::fusion::detail::invoke_impl<boost::function<void (int &)>,Sequence,1,false,true>' being compiled
with
[
Sequence=const boost::fusion::vector1<int>
]
main.cpp(16) : see reference to class template instantiation 'boost::fusion::result_of::invoke<boost::function<void (int &)>,const boost::fusion::vector1<int>>' being compiled
It's failing when trying to instantiate boost::result_of with a const Sequence. I've looked in boost\fusion\functional\invocation\invoke.hpp and there are two overloads of boost::fusion::invoke, one is const and the other is non-const.
I think that the Visual Studio 2013 compiler is attempting to instantiate the const version even though that is not the one that should be called. If I comment out the const version in invoke.hpp the example compiles fine.
Is this a bug with Visual Studio 2013 or boost-1.56?
Is there any workaround for this problem without modifying the boost sources?
I suspect the default for BOOST_RESULT_OF has changed for VS2013.
#define BOOST_RESULT_OF_USE_TR1
makes it compile. Chances are this bug is known and has been fixed in trunk, but you might want to report it still
I'm currently on vacation far away from my desktop, however I wanted to practice my c++ in particular with openCV, so I brought my laptop along. Given time and family constraints I didn't get everything set up in time with the libraries before flying.
I've set everything up with regards to VS 2010 as I recall doing on my desktop a while ago, but on compiling the test example on the openCV website (http://opencv.willowgarage.com/wiki/VisualC%2B%2B) I receive the following errors:
Error 3 error C2244: 'cv::Matx<_Tp,,>::diag' : unable to match function definition to an existing declaration C:\Program Files\OpenCV2.2\include\opencv2\core\operations.hpp 372
Error 4 error C2244: 'cv::Matx<_Tp,,>::diag' : unable to match function definition to an existing declaration C:\Program Files\OpenCV2.2\include\opencv2\core\operations.hpp 448
which in turn shows me:
template<typename _Tp, int m, int n> inline
Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const Matx<_Tp,MIN(m,n),1>& d)
{
Matx<_Tp,m,n> M;
for(int i = 0; i < MIN(m,n); i++)
M(i,i) = d[i];
return M;
}
template<typename _Tp, int m, int n> inline
Matx<_Tp, MIN(m,n), 1> Matx<_Tp, m, n>::diag() const
{
diag_type d;
for( int i = 0; i < MIN(m, n); i++ )
d.val[i] = val[i*n + i];
return d;
}
I've looked into this error on the msdn and have looked on the openCV forums, but I couldn't find record of this specific error and I'm not sure how to resolve it.
Is it also problematic that I'm running the 64 bit version of Windows 7? I read that openCV2.2 is compatible however previously while the programs would compile, it kept on saying the .dll files were missing even though the PATH variable and directories were correct.
Thanks,
Jean-Pierre
I had the same issue running Opencv2.2 on 32bit Win7 VS2010 and QT 4.7.2.
I doesn't seem to be an error that affects the actual function of code. When I turned code analysis off as Himanshu jain described above it fixed the problem.
It seems indeed that the option advanced compiler option "/analyze" causes this problem (I'm using OpenCV 2.2 with VS 2008 on Win XP 32bit). I could fix the first error:
In line 365, you got to replace Matx<_Tp,MIN(m,n),1> with diag_type, i.e. this
template<typename _Tp, int m, int n> inline
Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const Matx<_Tp,MIN(m,n),1>& d)
becomes
template<typename _Tp, int m, int n> inline
Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const diag_type& d)
Unfortunately, the 2nd error still occurs -- I found no way to get rid of it but to deactivate \analyze :-(
1>D:\OpenCV2.2\include\opencv2/core/operations.hpp(447) : error C2244: 'cv::Matx<_Tp,,>::diag':
unable to match function definition to an existing declaration
If you find a way to fix this, please let me know -- I think I'll go ahead and post a bug-report-ticket on OpenCV Trac now...