Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Jul 2013 20:32:00 +0200
From:      "O. Hartmann" <ohartman@zedat.fu-berlin.de>
To:        David Chisnall <theraven@FreeBSD.org>
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:  <20130710203200.5359fd18@thor.walstatt.dyndns.org>
In-Reply-To: <C8C94CF2-7D5A-471B-AD63-8E961AED6274@FreeBSD.org>
References:  <20130710155809.0f589c22@thor.walstatt.dyndns.org> <CD51F125-AE9E-4461-916D-CF583002B47D@FreeBSD.org> <20130710183315.725dfde0@thor.walstatt.dyndns.org> <C8C94CF2-7D5A-471B-AD63-8E961AED6274@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--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 <theraven@FreeBSD.org> wrote:

> On 10 Jul 2013, at 17:33, "O. Hartmann" <ohartman@zedat.fu-berlin.de>
> wrote:
>=20
> > 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".
>=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 <iostream>
> #include <typeinfo>
> #include <cmath>
> 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 <iostream>
#include <typeinfo>
#include <cmath>

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 <iostream>
#include <typeinfo>
#include <cmath>

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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130710203200.5359fd18>