Reputation: 4278
I have a cross-platform build. On a *nix platform using GCC, I use the __attribute__((warn_unused_result))
to notify the consumer of my API if a return value is not checked. I assumed that _Check_return
does the same thing on MSVC, but it doesn't appear to be working the way I expect.
The following code does not produce a warning as I expect. Warnings are set to /Wall
.
_Check_return_ _Must_inspect_result_ int foo()
{
return 100;
}
int main()
{
foo();
return 0;
}
Code compiles without warnings. What am I doing wrong (or what should I be using to generate warnings for unchecked return codes)?
Upvotes: 0
Views: 1620
Reputation: 355079
SAL annotations like _Check_return_
and _Must_inspect_result_
are only checked during code analysis builds (either by starting a code analysis build in the IDE or by building with the /analyze flag on the command line).
See "Understanding SAL" on MSDN for more information.
Upvotes: 4