1

Considering following code:

struct MyType{};

MyType myFunction() __attribute__ ((warn_unused_result))
{
    return MyType{};
}

int main()
{
    myFunction();
    auto storMyType = myFunction();
}

Not storing the return value of myFunction is a logical error and I want to have a compilation error on all compilers. Is there any equivalent for Visual Studio 2013?

Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211

1 Answers1

2

The annotation is _Check_return_

Annotates a return value and states that the caller should inspect it. The checker reports an error if the function is called in a void context.

However, I believe SAL annotations are only available in the Premium and Ultimate versions of Visual Studio.

MSDN: Annotating Function Behavior

OrangeDog
  • 36,653
  • 12
  • 122
  • 207