From owner-freebsd-toolchain@FreeBSD.ORG Wed Jul 10 17:04:20 2013 Return-Path: Delivered-To: freebsd-toolchain@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id A2DDED36; Wed, 10 Jul 2013 17:04:20 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from theravensnest.org (theraven.freebsd.your.org [216.14.102.27]) by mx1.freebsd.org (Postfix) with ESMTP id 6972D1DE8; Wed, 10 Jul 2013 17:04:20 +0000 (UTC) Received: from c120.sec.cl.cam.ac.uk (c120.sec.cl.cam.ac.uk [128.232.18.120]) (authenticated bits=0) by theravensnest.org (8.14.5/8.14.5) with ESMTP id r6AH4IpI000238 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Wed, 10 Jul 2013 17:04:18 GMT (envelope-from theraven@FreeBSD.org) Content-Type: multipart/signed; boundary="Apple-Mail=_EB9CE248-0AA2-4B95-B0D9-AEB68202583F"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) Subject: Re: CURRENT: CLANG 3.3 and -stad=c++11 and -stdlib=libc++: isnan()/isninf() oddity From: David Chisnall In-Reply-To: <20130710183315.725dfde0@thor.walstatt.dyndns.org> Date: Wed, 10 Jul 2013 18:04:16 +0100 Message-Id: References: <20130710155809.0f589c22@thor.walstatt.dyndns.org> <20130710183315.725dfde0@thor.walstatt.dyndns.org> To: "O. Hartmann" X-Mailer: Apple Mail (2.1503) Cc: FreeBSD CURRENT , freebsd-toolchain@FreeBSD.org X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jul 2013 17:04:20 -0000 --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" = wrote: > Hi David, >=20 > thanks for the fast response. >=20 > The code I was told to check with is this: >=20 > #include > #include > #include >=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 #include #include 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--