Introduction

I started a special STL include file because I always use warning level 4 and including STL stuff flooded me with warnings. After fiddling around for a while I found out that STL itself switches on warnings. This happens in the file yvals.h. Therefore a peculiar including technique is necessary.

The purpose is to keep all warnings in the own source and disable the STL warning noise. This is done by switching off the warnings before you include the STL stuff and restore the original warning state afterwards.

Before switching off the warnings the file yvals.h must be included to activate the files include guard and avoid a further change of the warning state.

MSKB article 'BUG: C4786 Warning Is Not Disabled with #pragma Warning' (Article ID: Q167355) describes a warning that can't be disabled. This occured to me using a map. I think the article sample is using a tree with itself uses a map.

ASSERT and TRACE

Because I'm not using MFC but got acquainted with ASSERT and TRACE I added some defines to have this feature with STL. This is in no relation with the warnings but is quite handy in my opinion.

You can use it like in MFC. I extended ASSERT to quit a function in the release build when the assert is false. Therefore you can find six additional asserts like ASSERT_RETURN, ASSERT_RETURN_FALSE and ASSERT_RETURN_NULL depending on the return type of your funciton. You can even quit control structures with ASSERT_BREAK and ASSERT_CONTINUE.

Usage

I'm using a macro system to specify with STL elements to use or a STL_USING_ALL to include all objects covered. The STL include file is not complete (just the objects I use frequently) and must be extended if necessary. You don't need to declare using namespace std;. This is done at the end of the include file.

To use it in your code (I always place it the precompiled header file):

Conclusion

The disabled warnings are not complete and I'm adding new stuff with every project I do. I think this is basic approach to get along with STL and warning level 4. I appreciate suggestions and additions to get it more complete.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

Compiler Warning (level 1) C4503

'identifier' : decorated name length exceeded, name was truncated

The decorated name was longer than the maximum the compiler allows (247), and was truncated. To avoid this warning and the truncation, reduce the number of arguments or name length of identifiers used.

To avoid including something you don't need, I cooked up some code until these remains were left. This seems to make #pragma warning(disable:4786) work reliably. Any attempy to further simplify this bizarre code thwarts its effect.