I learned about this little feature of GCC/Clang today:
Something * MyFunctionThatNeverReturnsNULL() __attribute__((returns_nonnull))
{
// code here that never returns NULL
}
[...]
int main()
{
Something * s = MyFunctionThatNeverReturnsNULL();
if (s) // useful: compiler generates a warning here since this test will always return true!
{
// do something
}
else
{
// do something else
}
}
This feature is useful because if I have calling code that is erroneously expecting a NULL return value to indicate failure, the __attribute__((returns_nonnull))
annotation allows the compiler to print a warning so that I can know to look at that code and fix it.
My question is, does MSVC have anything similar/equivalent so that the same type of warnings might be generated when compiling under Windows?