If I'm compiling a program that uses some standard C++ headers, I get all sorts of horrible warnings. For example, compiling the following program with cl.exe:
#include <iostream>
#include <list>
#include <string>
int main()
{
return 0;
}
Generates the following output:
cl test.cpp
test.cpp
C:\VC++2003\include\ostream(574) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\VC++2003\include\istream(828) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\VC++2003\include\istream(1064) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\VC++2003\include\ostream(479) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\VC++2003\include\ostream(471) : while compiling class-template member function 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::put(_Elem)'
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
C:\VC++2003\include\ostream(561) : see reference to class template instantiation 'std::basic_ostream<_Elem,_Traits>' being compiled
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
C:\VC++2003\include\ostream(479) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\VC++2003\include\ostream(471) : while compiling class-template member function 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::put(_Elem)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\VC++2003\include\ostream(922) : see reference to class template instantiation 'std::basic_ostream<_Elem,_Traits>' being compiled
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\VC++2003\include\istream(99) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\VC++2003\include\istream(89) : while compiling class-template member function 'bool std::basic_istream<_Elem,_Traits>::_Ipfx(bool)'
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
C:\VC++2003\include\istream(816) : see reference to class template instantiation 'std::basic_istream<_Elem,_Traits>' being compiled
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
C:\VC++2003\include\istream(99) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\VC++2003\include\istream(89) : while compiling class-template member function 'bool std::basic_istream<_Elem,_Traits>::_Ipfx(bool)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\VC++2003\include\istream(1054) : see reference to class template instantiation 'std::basic_istream<_Elem,_Traits>' being compiled
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\VC++2003\include\xstring(1453) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\VC++2003\include\xstring(1444) : while compiling class-template member function 'void std::basic_string<_Elem,_Traits,_Ax>::_Copy(std::basic_string<_Elem,_Traits,_Ax>::size_type,std::basic_string<_Elem,_Traits,_Ax>::size_type)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
C:\VC++2003\include\stdexcept(39) : see reference to class template instantiation 'std::basic_string<_Elem,_Traits,_Ax>' being compiled
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
Now there are various other headers and unnecessary warnings. For now I've had to suppress them on the command line with things like /wd4258 /wd4290 /wd4127 /wd4800 ... and many more that crop up. This obviously means I miss legitimate warnings in my own code.
Could there please be an option "Ignore warnings in standard header files" or something similar. I can't tell you how annoying this is!
Thanks
Mike

Option to supress warnings in standard headers?
Mojmir
I've encountered warnings in standard headers even with the /EHsc switch. My point is that since these are standard headers, I can't do anything about the warnings, I know the headers are correct, so it would be nice to be able to hide them all with one option.
edit: in fact, I should have chosen a better example for the code. I just hacked that together and didn't realise it was all the same warning.
RavenSensei1
Hi Mike: this is a known problem in Visual C++ 2003 with control-flow tracking and catch (...) blocks. I am 99.99% certain that this has been fixed in Visual C++ 2005.
Zheng Lu
Also which version of the compiler are you using I know that the Visual C++ 2005 Beta-2 compiler still had some problems with the Standard C++ Library header files.
jini shans
OK here we go... in actual fact these warnings are only output when I use the /O2 flag, so they be a result of some optimizations:
#include <list>
int main()
{
std::list<int> i;
return 0;
}
(Note I have to actually use the list template class in the code)
Then
cl /EHsc /W4 /O2 test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
test.cpp
c:\vc++2003\include\list(907) : warning C4702: unreachable code
c:\vc++2003\include\list(908) : warning C4702: unreachable code
c:\vc++2003\include\list(909) : warning C4702: unreachable code
c:\vc++2003\include\list(910) : warning C4702: unreachable code
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
---
Also, as for me saying there were lots of different warnings... I think this may be the only one. I'm guess I'm just used to lots of uneccessary warnings and jumped the gun a bit - I should have repro'd the problem better ;)
FrankLin1981
If you really want to disable these warnings in the header files I would do the following:
#pragma warning(push) // Save the current warning state
#pragma warning(disable:4258)
#pragma warning(disable:4290)
#pragma warning(disable:4127)
#pragma warning(disable:4800)
#include <list>
#include <string>
#pragma warning(pop) // Restore all warnings to the previous state