Visual C++: Letting C++ programmers get away with new murder without warning

Consider Visual C++.

This always correct code emits a completely useless warning:

 

 

This never ever correct code doesn’t emit any warning at all:

Visual C++ is a totally awesome piece of technology.  So why doesn’t it work the way I want it to?

3 Responses to “Visual C++: Letting C++ programmers get away with new murder without warning”


  • The latter example is heaps of fun, no doubt.

  • The actually always correct code for the catch clause is

    catch (const std::exception&)

    Write it this way, and you don’t get an error message. You are signaling your intention to handle an exception with a particular signature, but plan not to actually use the exception.

    • Your code is correct too. But there’s absolutely no harm in specifying the variable name (“ex”). Especially if you got there either by (a) intentionally deleting code in the exception handler such that the exception variable is no longer used, or (b) using code generated by a template (“code snippet”).

      (I find the “unreferenced formal parameter” warnings completely useless as well. “‘argv’ : unreferenced formal parameter”.)

Leave a Reply