Sun Studio 12.1 打印警告
Warning: The last statement should return a value.
经常用于这样的功能:
int f()
{
/* some code that may return */
// if we end up here, something is broken
throw std::runtime_error("Error ...");
}
很明显,我们不需要函数末尾的返回值。我犹豫插入类似的东西
// Silence a compiler warning
return 42;
在这样一个函数的末尾,因为无论如何它都是死代码。对于更复杂的返回类型,实际上可能很难构造一个“合理的”虚假值。
消除这种警告的推荐方法是什么?