Consider the following C++ code (taken from
http://www.cplusplus.com/reference/system_error/error_code/error_code/)
// error_code constructors
#include <iostream> // std::cout
#include <cmath> // std::sqrt
#include <cerrno> // errno
#include <system_error> // std::error_code, std::generic_category
// std::error_condition
int main()
{
errno=0;
std::sqrt(-1.0); // errno set to EDOM
std::error_code ec (errno,std::generic_category());
std::error_condition ok;
if (ec != ok) std::cout << "Error: " << ec.message() << '\n';
return 0;
}
Compiled with gcc this code produced an error display.
Compiled with clang (in my Macintosh) this code display absolutely NOTHING.
I tried compiling using -std=c++11, -std=c++14 with the same results.
Is this a bug in clang?
As far as I understand this this code
1) Sets errno to zero
2) Calls sqrt with a double constant of -1.0 This should set errno.
3) Calls the constructor with an error code (errno) and a generic
category. This should produce an object of type error_code
4) Calls the constructor with default arguments. This should produce an
error code object with no errors
5) Compares the two error codes. If they are different displays a
message. They must be different since errno should have been set by sqrt.
But for clang they aren't.
Is this a bug in clang?