[cfe-dev] Objective-C and C++0x nullptr

Jonathan Sauer jonathan.sauer at gmx.de
Mon May 30 05:26:00 PDT 2011


Hello,

>> while naively replacing NULL with nullptr in my code, I stumbled upon the following.
> 
> You shouldn't need to do that.  NULL should be a #define for nullptr in C++ 2011 mode, or for something more relevant to the language settings in other modes.

Well, I was trying to initialize a std::unique_ptr with an explicit NULL, which resulted in an
ambiguity during overload resolution of the constructor (there is one taking a nullptr_t as well
as one taking a T*). So I took that opportunity to convert this part of my code base to C++0x,
too (and use std::unique_ptr's default constructor ...).

Clang's behaviour seems to be correct here, as according to FDIS 4.10p1, "0L" can be converted to a
pointer type as well as a std::nullptr_t.

Reading FDIS 18.2p3, it does not seem that NULL is required to be a #define for nullptr. Indeed, the
footnote there explains that "0" is a valid definition (and libc++ currently uses the system's
stddef.h's definition).


Jonathan





More information about the cfe-dev mailing list