ObjC++ is great and it's possibilities to shoot legs are countless.
One of them is returning C++ objects by value from ObjC methods.
In case of normal program flow that works just fine.
But in case of calling methods from nil objects they return... just garbage.
No constructors/destructors called and you get a C++ object in undefined state with garbage inside.
This issue causes some fun with debugging when mixing C++ lambdas and ObjC blocks:
void A(std::function<void()> a)
{
if(a) a();
}
void B(void (^a)())
{
if(a) a();
}
int main(int argc, const char * argv[])
{
A( []{} ); // <- ok
A( nullptr ); // <- ok
A( ^{} ); // <- ok
B( ^{} ); // <- ok
B( (void(^)(void)) nil ); // <- ok
A( (void(^)(void)) nil ); // <- crash
return 0;
}
Happy debugging!