Edit

Share via


Warning C28205

'function': _Success_ or _On_failure_ used in an illegal context

The _Success_ and _On_failure_ annotations can only be used on function return values.

Examples

This sample shows how the warning finds a misplaced SAL annotation:

#include <sal.h>

// Oops, _Success_ is not valid in parameter lists, should be moved to return value.
bool GetValue( _Success_(return != false) _Out_ int *pInt, bool flag)
{
   if(flag) {
      *pInt = 5;
      return true;
   } else {
      return false;
   }
}

To correct the issue, move the SAL annotation to the return value:

#include <sal.h>

_Success_(return != false)
bool GetValue(_Out_ int *pInt, bool flag)
{
   if(flag) {
      *pInt = 5;
      return true;
   } else {
      return false;
   }
}

See also

Understanding SAL