From owner-freebsd-current@FreeBSD.ORG Wed Jul 10 18:32:08 2013 Return-Path: Delivered-To: freebsd-current@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 46FD387B; Wed, 10 Jul 2013 18:32:08 +0000 (UTC) (envelope-from ohartman@zedat.fu-berlin.de) Received: from outpost1.zedat.fu-berlin.de (outpost1.zedat.fu-berlin.de [130.133.4.66]) by mx1.freebsd.org (Postfix) with ESMTP id 038DD12E3; Wed, 10 Jul 2013 18:32:07 +0000 (UTC) Received: from inpost2.zedat.fu-berlin.de ([130.133.4.69]) by outpost1.zedat.fu-berlin.de (Exim 4.80.1) with esmtp (envelope-from ) id <1UwzBO-001rKc-RC>; Wed, 10 Jul 2013 20:32:06 +0200 Received: from e179143131.adsl.alicedsl.de ([85.179.143.131] helo=thor.walstatt.dyndns.org) by inpost2.zedat.fu-berlin.de (Exim 4.80.1) with esmtpsa (envelope-from ) id <1UwzBO-0003BP-MM>; Wed, 10 Jul 2013 20:32:06 +0200 Date: Wed, 10 Jul 2013 20:32:00 +0200 From: "O. Hartmann" To: David Chisnall Subject: Re: CURRENT: CLANG 3.3 and -stad=c++11 and -stdlib=libc++: isnan()/isninf() oddity Message-ID: <20130710203200.5359fd18@thor.walstatt.dyndns.org> In-Reply-To: References: <20130710155809.0f589c22@thor.walstatt.dyndns.org> <20130710183315.725dfde0@thor.walstatt.dyndns.org> Organization: FU Berlin X-Mailer: Claws Mail 3.9.2 (GTK+ 2.24.19; amd64-portbld-freebsd10.0) Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/a3Zxzw.Wnu5iEEcQW081qGU"; protocol="application/pgp-signature" X-Originating-IP: 85.179.143.131 Cc: FreeBSD CURRENT , freebsd-toolchain@FreeBSD.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jul 2013 18:32:08 -0000 --Sig_/a3Zxzw.Wnu5iEEcQW081qGU Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Wed, 10 Jul 2013 18:04:16 +0100 David Chisnall wrote: > On 10 Jul 2013, at 17:33, "O. Hartmann" > wrote: >=20 > > 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". >=20 > 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: >=20 > std::cout << typeid(std::isnan(1.0)).name() << "\n"; >=20 > 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: >=20 > #include > #include > #include > using namespace std; >=20 > int > main(void) > { >=20 > cout << typeid(isnan(1.0)).name() << "\n"; >=20 > } >=20 > 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. >=20 > 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 >=20 > A fix for your code is to ensure isnan() and isinf() are explicitly > namespaced. Potentially, this may also work: >=20 > using std::isinf; > using std::isnan; >=20 > David >=20 I tried in the test code I provided using=20 #include #include #include int main(void) { std::cout << typeid(std::isnan(1.0)).name() << "\n"; } now std::isnan(). The result is the same, it flags "INT". Using=20 #include #include #include using namespace std; int main(void) { std::cout << typeid(std::isnan(1.0)).name() << "\n"; } which is considered "bad coding" also results in "INT" (it gives "i"). So, is this woth a PR? Oliver --Sig_/a3Zxzw.Wnu5iEEcQW081qGU Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQEcBAEBAgAGBQJR3ailAAoJEOgBcD7A/5N86YsH+wZrHf5AyIHKAXV6iWe3FAvK Zlazcyk6Jy8SPyoel0oLr/Ox8oLYw1i6uy1eAZA63EgS7k5LDVHsEDXctn3PMiDN UML3OsqP+e6Ch9Ohkhelk5HIuhqCum4Pt4YGWTKbbEfVj1v4v6NvXscCmlO1CSKn 256QCaX92DQIaKzrdQCotfdgHoUuzPvSwXdHwAslbTKOVBSBmRz0DCZaJvmSx8zt vTqHSvVBApDEUG1JCI4jN8E46GVjNpa2GzzOSwh16tQWR4Dixdo9uM95+FmlkL9D 8egZuGkEwPqjMuxSYe1qMtpP5MrlN6N0SvZL5MCtJ7Qv790/cCbqLG9XNkmf9po= =AzRw -----END PGP SIGNATURE----- --Sig_/a3Zxzw.Wnu5iEEcQW081qGU--