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

Jonathan Sauer jonathan.sauer at gmx.de
Mon May 30 04:07:56 PDT 2011


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?


With many thanks in advance,
Jonathan





More information about the cfe-dev mailing list