Sign in to follow this  
  • entries
    195
  • comments
    198
  • views
    103763

warning levels

Sign in to follow this  
SiCrane

70 views

There are some days when I want my compiler to be a little more strict than normal. Today I was working with someone else's C++ code, and it used std::string in many places. So far so good. Except he he was comparing the result of string::find() against -1 instead of string::npos. This is not so good, but the compiler let it pass without comment.

I'm here thinking, "Hello. -1 signed number, string::find() returns a unsigned, I'm supposed to get a unsigned/signed comparison warning here."

But now that I think about it, I think I'd like a super strict warning mode. Let's call it /W36. I want this mode to warn me about widening conversion, assignment between variables of different typedefs, etc. This is mostly to catch potentially non-portable code that relies on certain typedefs being used for STL implementations, etc.

Maybe what I really need to do is drag my "barely standard" STL project back from mothballs. It's your typical annoying template library: only things that are required to be primitive types are; everything else is a class type. Also triggers assertions at a drop of a hat. Basically it tries to define undefined behaviour as being either non-compiling or crashing the system. I only really worked on the vector implementation, but it was a doozy. Iterators worked on a observer pattern, so when a reallocation occured, they actually set a invalidated flag so they could assert if you tried to use them.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now