gpt4 book ai didi

c++ - 相当于 __attribute__ 的 Visual Studio ((warn_unused_result))

转载 作者:行者123 更新时间:2023-11-30 03:59:35 26 4
gpt4 key购买 nike

考虑以下代码:

struct MyType{};

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

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

不存储 myFunction 的返回值是一个逻辑错误,我希望所有编译器都出现编译错误。 Visual Studio 2013 是否有任何等效项?

最佳答案

注解是_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.

但是,我认为 SAL 注释仅在 Visual Studio 的高级版和旗舰版中可用。

MSDN: Annotating Function Behavior

关于c++ - 相当于 __attribute__ 的 Visual Studio ((warn_unused_result)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26842362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com