Boost logo

Boost :

Subject: Re: [boost] Failures for GCC 4.4.1 with gnu++0x
From: Beman Dawes (bdawes_at_[hidden])
Date: 2009-09-05 12:47:59


On Sat, Sep 5, 2009 at 8:51 AM, Christopher
Schmidt<mr.chr.schmidt_at_[hidden]> wrote:
> I think gcc behaves correctly.
>
> The non-0x pair has a two-argument constructor taking const references to T1
> and T2 (20.2.2p2). Therefore the 0 you pass is directly regarded be the null
> pointer constant.
> The 0x pair has a 1...N argument _template_ constructor (20.2.2p6 of the
> current draft). The 0 is regarded to be an int, and therefore you are
> passing an actual int to initialize a pointer.
>
> std::pair<int, int*> x(0,nullptr);
> or
> std::pair<int, int*> x(0,static_cast<void*>(0));
>
> should work fine though.

Since nullptr is a C++0x feature, that won't work for code that also
has to run on c++03 compilers.

static_cast<void*>(0) isn't valid since a conversion from void* to
int* isn't valid.

static_cast<int*>(0) works OK.

What about a macro "#define nullptr 0" that is only defined if the
compiler does not support C++0x nullptr? It usually is a really bad
idea to give a macro a lowercase name, but isn't this a really special
case because nullptr is a C++0x keyword?

--Beman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk