Date: Wed, 10 Jul 2013 18:04:16 +0100 From: David Chisnall <theraven@FreeBSD.org> To: "O. Hartmann" <ohartman@zedat.fu-berlin.de> Cc: FreeBSD CURRENT <freebsd-current@FreeBSD.org>, freebsd-toolchain@FreeBSD.org Subject: Re: CURRENT: CLANG 3.3 and -stad=c++11 and -stdlib=libc++: isnan()/isninf() oddity Message-ID: <C8C94CF2-7D5A-471B-AD63-8E961AED6274@FreeBSD.org> In-Reply-To: <20130710183315.725dfde0@thor.walstatt.dyndns.org> References: <20130710155809.0f589c22@thor.walstatt.dyndns.org> <CD51F125-AE9E-4461-916D-CF583002B47D@FreeBSD.org> <20130710183315.725dfde0@thor.walstatt.dyndns.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--Apple-Mail=_EB9CE248-0AA2-4B95-B0D9-AEB68202583F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 10 Jul 2013, at 17:33, "O. Hartmann" <ohartman@zedat.fu-berlin.de> = wrote: > Hi David, >=20 > thanks for the fast response. >=20 > The code I was told to check with is this: >=20 > #include <iostream> > #include <typeinfo> > #include <cmath> >=20 > int > main(void) > { >=20 > std::cout << typeid(isnan(1.0)).name() << "\n"; >=20 > } >=20 >=20 > If I compile it with=20 >=20 > c++ -o testme -std=3Dc++11 -stdlib=3Dlibc++ source.cc >=20 > and run the binary, the result is "i" which I interpret as "INT". I believe there is a bug, which is that the math.h things are being = exposed but shouldn't be, however it is not the bug that you think it = is. Try this line instead: std::cout << typeid(std::isnan(1.0)).name() << "\n"; We have a libm function, isnan(), and a libc++ function, std::isnan(). = The former is detected if you do not specify a namespace. I am not sure = what will happen if you do: #include <iostream> #include <typeinfo> #include <cmath> using namespace std; int main(void) { cout << typeid(isnan(1.0)).name() << "\n"; } This is considered bad form, but does happen in some code. I am not = certain what the precedence rules are in this case and so I don't know = what happens. To properly fix this, we'd need to namespace the libm functions when = including math.h in C++. This would also include fixing tweaking the = macros. =20 A fix for your code is to ensure isnan() and isinf() are explicitly = namespaced. Potentially, this may also work: using std::isinf; using std::isnan; David --Apple-Mail=_EB9CE248-0AA2-4B95-B0D9-AEB68202583F Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.18 (Darwin) Comment: GPGTools - http://gpgtools.org iQIcBAEBAgAGBQJR3ZQRAAoJEKx65DEEsqId2pgQALR81QLfm7K7mE+qxwrS9/dr pcs2iSLUAX6ZnHGyhENAHOWBrpYofWFAtjlOmOcKjs3cPHq5H3dw5CgSEDqke+iB AlNeg1HC5iuIiwzlYGuXBr4cvbZ3oEDv0I+qCUS7T4Puidv5BHik+dcqbpJzgi9b J3k5AMhTYOI834qV7VJkTmZ74U/okJgywy5ebYsBx4OicPg8LTFONwSnGzHhimpC mjki3KlosYX8x9mErxdLBnkoMRuEYcBHO3XnJKK3fesC8eAH9Drr9wWaScHjsW59 OrjQ5sGd/TOMyhZIVmr0rtWRl+X06J3TXA3W+Ama6VuwDeXI5yZM5Udvd+RTxDs8 jMcZROkUOnDUn8LZEkP7X47rUe5WxSmvclhLh4yW1NEa8vnTQ4V4vFFH/Dmr6YNi kz14k6hsdpx3EzAH45AI1povQnkKGocpVyWa+DRdE65PlQCsp4HibjCgp7Q9o3dw 6SqAKw2o01925yCMIBZEdhawOjlhFFijfgbceK+KRusZukl/0D9pWmtRKphkpVF3 tbl/mygYkW4OKCxLvoVUmrXsqMXnjkqcdI7ozrTM6GDDryTkt3vK8Rd0ToEH6b4e U7lCkmo84YhS2BCc3riEiGLqJcNYjv6p4UkLlieVUv0+YrlGHgMKJUovW5ppJhBI WKOZwmL/ntfhB0IpCl6M =pI2H -----END PGP SIGNATURE----- --Apple-Mail=_EB9CE248-0AA2-4B95-B0D9-AEB68202583F--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?C8C94CF2-7D5A-471B-AD63-8E961AED6274>