I was under impression Visual C++ 10 had built-in static_assert. However when I compile the following
void test()
{
static_assert( sizeof( char ) == 1, "" );
}
I get
error C3861: 'static_assert': identifier not found
What am I doing wrong and how do I use static_assert in Visual C++ 10?
I was under impression Visual C++ 10 had built-in static_assert.
It indeed does and this compiles perfectly fine for me:
int main(){
static_assert( sizeof( char ) == 1, "" );
}
Do you have any other errors in your code? Maybe this error is a result of the chain of other erros.
The reason was Visual Studio was set up to use Visual C++ 9 compiler (the one which is shipped with Visual Studio 2008). I don't know how it happened, perhaps the wizard configuring Visual Studio imported paths to the previous version.
The settings is changed in project properties - on "VC++ Directories" pane. The easy way to check which compiler is invoked is to add -Bv option to the compiler command line which will make the compiler report its version.
Related
I was trying to build the Goptical package (https://savannah.gnu.org/projects/goptical ) in windows using Visual Studio 2019. It uses DPP library (https://code.ssji.net/hg/ ) which throws errors when building under Visual Studio. The Linux build with gcc goes smooth as expected, but I need this on windows with visual studio.
The errors come up from delegate classes which are nested template classes further wrapped inside using macros. Tried debugging but visual studio does not seem to pinpoint the exact location of the error, but instead point to last line which triggered the error.
Is there any mechanism by which we can see the macro definitions rolled back step by step? Or, an intermediate output that we could examine to debug this step by step? Posting the offending code and error details below:
1> delegate(578,1): error C2059: syntax error: ','
1> delegate(578): message : see reference to class template instantiation 'dpp::delegate_bind<base,R(void),3>' being compiled
Code:
#if DPP_DELEGATE_ARGC >= 2
_DPP_DELEGATE(2)
_DPP_DELEGATE_FUNC(2)
_DPP_DELEGATE_MEMBER(2)
_DPP_DELEGATE_MEMBER_THIS(2)
_DPP_DELEGATE_BIND(1, 1, 1, _DPP_DELEGATE_BTDEFS(1, 0), _a0, a0);
_DPP_DELEGATE_BIND(2, 1, 1, _DPP_DELEGATE_BTDEFS(1, 1), a0, _a0);
_DPP_DELEGATE_BIND(3, 0, 2, _DPP_DELEGATE_BTDEFS(2, 0, 1), _a0, _a1);
#endif
I suggest that you could set Yes in Properties->C/C++->Preprocessor->Preprocess to file. Then, you could see the macro definitions in XXX.i file in the debug floder of the project.
I am trying to compile the following piece of code in Visual Studio 2015 (Community version) but encountering the error shown further down below.
/*****Source Code Start*******/
constexpr char const* GetStatusAsCString(Status compute)
{
switch (compute)
{
case armnn::Status::Success: return "Status::Success";
case armnn::Status::Failure: return "Status::Failure";
default: return "Unknown";
}
}
/*****Source Code End*******/
Error message:
> Error (active) a constexpr function must contain exactly one return
> statement ArmNN_MnistTF_64b c:\armnn\armnn-devenv\armnn\include\armnn\TypesUtils.hpp 22
Note that i have made sure of the following settings:
Set the compiler front end as Clang in VS 2015:
I have set the C++ standard as C++14.
Can anyone please advise me on what else am I missing? Been struggling with this error for sometime now.
Visual Studio 2015 does not fully implement C++14 even as of VS 2015 Update 3 although it has a lot of it.
Specifically, N3652 Extended constexpr is not implemented until VS 2017. You should upgrade to the latest VS 2017 Community edition update (which at this point is 15.7)
See Visual C++ Language Conformance
I am using Visual Studio 2015 Update 3.
I get a fatal error:
(code C1001) : An internal error has occurred in the compiler.
Here is the code :
template<typename T>
constexpr T epsilon = std::numeric_limits<T>::epsilon();
I read it was fixed in Visual Studio Update 2. Can someone explain me why I am getting this error? Thanks in advance.
Any internal error (ICE) is a compiler bug. You get it because you have happened to trigger that bug. For this compiler you can report it at Microsoft Connect.
For such a report you need an example with an expected correct result, and the erroneous result.
The following test program compiles & runs nicely with MinGW g++ 5.1
#include <limits>
template<typename T>
constexpr T epsilon = std::numeric_limits<T>::epsilon();
#include <iostream>
using namespace std;
auto main() -> int
{
cout << epsilon<double> << endl;
}
Output:
2.22045e-016
With Visual C++ 2015 update 2 it produces an ICE:
foo.cpp(10): fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\cxxfe\sl\p1\c\symbols.c', line 28114)
To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
foo.cpp(10): note: see reference to variable template 'const double epsilon' being compiled
Compiler version:
> cl /nologo- 2>&1 | find "++"
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23725 for x86
I've raised this as a bug with Microsoft, but they have had a fix since early 2017 which has not been released from what I can see as of today.
I've also provided a project on GitLab and given information to Microsoft for this project here: https://gitlab.com/cppocl/tostring
Loading the .sln and compiling currently crashes with Visual Studio 2015 update 2 or 3, and Visual Studio Enterprise 2017 version 15.3.1.
It does seem that the combination of template and constexpr causes the compiler to crash.
I've seen reports for Visual Studio 2017 describing similar types of problems.
This link says fixed pending release:
https://developercommunity.visualstudio.com/content/problem/18155/msvc-2017-c-fatal-error-c1001-constexpr-initializa.html
Visual Studio 2015 backlog of bugs relating to constexpr is here:
https://blogs.msdn.microsoft.com/vcblog/2015/12/02/constexpr-in-vs2015-update-1/
EDIT:
I also don't believe changing optimization settings will make any difference, as has been recommended in other posts.
I have experimented with these settings and applied recommended patches without success so far.
I have C++ code in a project which behaves differently with Visual Studio 2010 and VS 2015.
if(return_val != 0)
{
ACE_OS::set_errno_to_last_error ();
result->set_error(errno);
}
return_val is the the return value of a prior function which has failed. So the next step is to capture error value.
In VS 2010
When result->set_error(errno) is called, while debugging, the control goes to the function _errno() , defined in source \VC\crt\src\dosmap.c.
In VS 2015
The source dosmap.c is not found.
The macro expansion for errno must be in a different place I suppose. But the behaviour should be same
Do I need to make any change in the VS settings for 2015?
Any help would be useful.
I think you have not installed the source files for the library. This would explain why it can't find the file.
errno is a strange variable, and is thread-local, and macro'ed in both platforms. What is happening in ACE_OS::set_errno_to_last_error ();?
If the function is not setting the errno value, that would explain the behavior differences.
I am getting run time crash in the following piece of code and not able to debug also. Please review and let me know what's going on.
// CppConsole.cpp : Defines the entry point for the console application.
//#include "stdafx.h"#include <iostream>#include <assert.h>
class Test : public std::tr1::enable_shared_from_this<Test>
{
public:
Test():x(0),y(0),z(0){};
int x;
float y;
double z;
};
int _tmain(int argc, _TCHAR* argv[])
{
std::tr1::shared_ptr<Test> t1(new Test);
std::tr1::shared_ptr<Test> t2 = t1->shared_from_this();
return 0;
}
I have include all the headers and the program is compiling fine. This is the error i am getting:
CppConsole.exe - Entry Point Not Found The procedure entry point
?_Xweak#tr1#std##YAXXZ could not be located in the dynamic link
library MSVCP90D.dll
If I comment out this line
std::tr1::shared_ptr t2 = t1->shared_from_this();
the program runs without crashing.
Update: Question can be closed for now. I will try to install VS feature pack and see weather the program executes without any crashes.
Googled it (The procedure entry point ?_Xweak),found this : http://blog.nilretain.org/
EDIT : I Build and Run it successfully on my msvc 2008 on xp-sp3 ,which has later version of msvcp90d.dll.
Maybe you can download and install the latest redist-version of msvc90 and rebuild.
EDIT: your dependencies says something is missing. check this out :
http://answers.yahoo.com/question/index?qid=20090623140325AAInugo
You need a template argument:
std::tr1::shared_ptr<Test> t1(new Test);
std::tr1::shared_ptr<Test> t2 = t1->shared_from_this();
The compiler should report an error if it is not present. (Visual C++ 2010 does)
It appears that your compiler is not linking against a DLL with the needed runtime functions. For instance, if you added the headers to your include path, but don't link to the latest version of the C++ runtime (check your project's settings), or installing the Visual C++ 2008 feature pack didn't work, or you installed the feature pack but then tried to compile from Visual Studio 2005, etc.
Basically the "process the source code (including headers)" step is working fine, but the "link all the DLLs" step is failing. And it's failing because the runtime you're linking against doesn't have the needed functions for shared_ptrs or weak_ptrs.
I had this problem when developing under M$ Windows SP3 with M$ Visual Studio 2008. I tried and combined many hints that I could find on the web. To no avail. The solution was simple, I had to install SP1 pack for M$ Visual Studio 2008!
The thing is that my external DLLs used C++ TR1 functions that I was not aware of. The M$ Visual Studio 2008 without SP does not have the right runtime DLLs.
So, just make sure you have that SP1 for your M$ Visual Studio 2008 first before trying any other solution.