I'm finding __attribute__ ((warn_unused_result))
to be very useful as a means of encouraging developers not to ignore error codes returned by functions, but I need this to work with MSVC as well as gcc and gcc-compatible compilers such as ICC. Do the Microsoft Visual Studio C/C++ compilers have an equivalent mechanism ? (I've tried wading through MSDN without any luck so far.)
It's _Check_return_
. See here for examples of similar annotations and here for function behaviour. It's supported since MSVC 2012.
Example:
_Check_return_
int my_return_must_be_checked() {
return 42;
}