我从来没有见过[[ noreturn ]]之前用过无void返回函数。我可以在非无效返回函数上使用[[noreturn]]吗?
以下定义清楚吗?
[[ noreturn ]] int function();
int function(){
while(true){/* impl */}
return 0;
}
返回类型必须是int
究其原因,是因为函数是通过一个函数指针传递给另一个函数。
因此,假设主叫看起来是这样的:
//call the non-returning function
int var = (*fptr)();
//use var some way (even though the function will never actually return)
std::cout << var;
将本次展览任何一种未定义行为?
您可能会遇到迂腐麻烦,并假定执行的结果是无限循环结束。 ([link](http://blog.regehr.org/archives/161)) – chris
@chris我希望用[[maybe_unused]]标记返回值。 –
从您发布的链接:*如果具有此属性的功能实际返回,则行为未定义。* – 101010