Visual Studio warnings

I found it useful to change some of the warnings generated by Visual Studio.

For instance, this statement:

if (num = 10) { doSomething(); }

Generates a warning, but I cannot see any case where this would not be a bug. So I change this warning and some others to errors: like this:


#pragma warning (error: 4715)
#pragma warning (error: 4706)
#pragma warning (error: 4553)    // '==' : operator has no effect; did you intend '='?
#pragma warning (error: 4150)    // deletion of pointer to incomplete type
#pragma warning (error: 4390)    // empty controlled statement found;
#pragma warning (disable: 4996)  // openf is dangerous (not!)

Now, there’s no way you can ignore it. By the way, there is a bug in Visual Studio, sometimes it won’t flag warning mentioned above at all.

Advertisements

2 Responses to Visual Studio warnings

  1. MrMorf says:

    if (num = 10) { doSomething(); }

    You checking the result of an assignment, which in this example will always be true
    as 10 != 0 (but this is dependant on operator overloads)

    the code is the came as

    num = 10;
    doSomething();

    The compiler is correct, and this warning is indeed very valuable..

    You are obfuscating whole intention.
    Is the intention to check the value, or assign the value?

    Anyone reading this line of code will automatically think its an equality operator, and not an assignment.
    Careful re-reading will spot the intention.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: