
Boris Gubenko wrote:
Test error_code_test[_dll] fails on HP-UX and AIX and I'd expect it to fail on Tru64 also (Tru64 results are currently not on the web).
The test checks message for error code -1 in both system and posix category and expects it to be "Unknown error". For system category:
ec = error_code( -1, system_category ); std::cout << "error_code message for -1 is \"" << ec.message() << "\"\n"; BOOST_CHECK( ec.message().substr( 0, 13) == "Unknown error" );
IIUC, the assumption is that strerror(invalid-error-code) either returns a pointer to a string starting with "Unknown error", which is the case on Linux -- see below, or returns a null pointer in which case libs/system/src/error_code.cpp maps it to "Unknown error" string:
const char * c_str = std::strerror( ev ); return std::string( c_str ? c_str : "Unknown error" );
The problem with this assumption is that there is no requirement in the C standard that the message string generated by strerror() for an invalid error code starts with "Unknown error" -- see excerpt from C99 below. For example, on HP-UX, strerror() returns an empty string and on Tru64 it returns "Error -1 occurred."
As for the null pointer, strerror() cannot return it -- again, see excerpt from C99 below. X/Open explicitly states that strerror() may signal error by setting errno, but not by returning any particular value:
" Upon successful completion, strerror() returns a pointer to the generated message string. On error errno may be set, but no return value is reserved to indicate an error. "
It does not mean that error_code.cpp should not check for a null pointer as a precaution against non-conformant implementation of strerror().
It's in there because that's what Microsoft does, and I happened to start testing on Windows.
In libs/system/test/error_code_test.cpp, the check for the message string corresponding to error code -1 should either be conditionalized for different platforms or removed.
I think it should be conditional for various platforms. The test was added because of a reported crash, so I really do want to continue to do some testing of the return. But it really does need to be conditional. Thanks, --Beman