I'm working under Sun Studio 12.3 on SunOS 5.11 (Solaris 11.3). Its providing a spurious warning:
"<file.h>", line 1: Warning: "<function>" is expected to return a value.
The function is part of a base class interface and looks like so. I only mention the base class interface to avoid the "why would you do that" discussions. A non-member function like below is enough to trigger it.
int foo()
{
throw runtime_error("Not implemented");
}
I found mention of similar problems. For example, the Xapian-core change log states:
- Disable " is expected to return a value" warning from Sun's C++
compiler, as it fires for functions ending in a "throw" statement. Genuine
instances will be caught by compilers with superior warning machinery.
According to SunStudio C++ compiler pragma to disable warnings, I can use -erroff=voidretw
. I'm concerned about -erroff=voidretw
because it might suppress valid findings. Also, if I go with the #pragma
, then I need to push and pop it to avoid cross pollinating into user code. I don't know how to push and pop warning states under Sun Studio.
My question is, how do I disable the warning for the one function in the header under Sun Studio?
This looks like a duplicate even though the message is different: How to silence 'The last statement should return a value' warning? I think I am going to vote to close this as a duplicate.