Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C++ problem

33 views
Skip to first unread message

jacobnavia

unread,
Jul 18, 2018, 5:09:06 AM7/18/18
to
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?

Ian Collins

unread,
Jul 18, 2018, 5:17:02 AM7/18/18
to
Old clang?

$ clang++ -std=c++14 x.cc; ./a.out
Error: Numerical argument out of domain

$ g++ -std=c++14 x.cc; ./a.out
Error: Numerical argument out of domain

$ clang++ --version
clang version 7.0.0-svn337135-1~exp1+0~20180715204310.423~1.gbp8ac377
(trunk)
g++ --version
g++ (Ubuntu 8-20180414-1ubuntu2) 8.0.1 20180414 (experimental) [trunk
revision 259383]

Even an old one:

$ clang++-4.0 -std=c++14 x.cc; ./a.out
Error: Numerical argument out of domain

--
Ian.

jacobnavia

unread,
Jul 18, 2018, 3:54:18 PM7/18/18
to
Le 18/07/2018 à 11:16, Ian Collins a écrit :

> Old clang?
>

Exactly. That was the problem. Thanks Ian.
jacob
0 new messages