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

Sebastian Redl sebastian.redl at getdesigned.at
Mon May 30 04:45:50 PDT 2011


On 30.05.2011 13:07, Jonathan Sauer wrote:
> Hello,
>
> while naively replacing NULL with nullptr in my code, I stumbled upon the following. Take this
> program:
>
> @interface NSOpenGLPixelFormat
> {
> }
> @end
>
> int main(int, char**)
> {
> 	NSOpenGLPixelFormat* p = 0;
> 	if (p == nullptr)
> 		;
> }
>
>
> When compiling this with clang r131897 and -x objective-c++, clang produces the following error:
> "invalid operands to binary expression ('NSOpenGLPixelFormat *' and 'nullptr_t')"
>
> Now, nullptr is a C++0x constant, and NSOpenGLPixelFormat is an Objective C class, but a pointer
> to it is still a pointer and thus should be comparable against nullptr.
>
> I think. Although I don't think the interaction between Objective-C and C++0x has been defined
> (yet).
>
> What do *you* think?
Clang handles pointers to ObjC types and normal types differently. That 
said, it would make sense to make nullptr be a proper ObjC pointer null 
constant as well. This would obviously be a language extension. If you 
want this, you should open a feature request in bugzilla.

Sebastian



More information about the cfe-dev mailing list