2011-03-28 13:22:57 +00:00
|
|
|
#import "Testing.h"
|
2011-03-21 11:52:30 +00:00
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
|
2011-03-28 13:22:57 +00:00
|
|
|
#if defined(TESTDEV)
|
2011-03-28 13:57:27 +00:00
|
|
|
|
2011-03-21 11:52:30 +00:00
|
|
|
#if !__has_feature(objc_nonfragile_abi)
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
START_SET("Unified exception model")
|
|
|
|
SKIP("Unified exception model not supported")
|
|
|
|
END_SET("Unified exception model")
|
2011-03-22 19:47:10 +00:00
|
|
|
return 0;
|
2011-03-21 11:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests whether void* catches Objective-C objects thrown as exceptions.
|
|
|
|
* According to John McCall at Apple, the correct behaviour is not to catch
|
|
|
|
* them in void* (which makes sense - void* is effectively a restricted
|
|
|
|
* catchall, and we don't want to be catching foreign exceptions there because
|
|
|
|
* we don't know what to do with them). In fact, the current behaviour on OS X
|
|
|
|
* (with g++, not tested with clang++) is not simply to not catch them, it is
|
|
|
|
* also to crash with a segfault. Current behaviour with clang + libobjc2 is
|
|
|
|
* to do the Right Thing™.
|
|
|
|
*/
|
|
|
|
int main(void)
|
|
|
|
{
|
2011-03-22 19:47:10 +00:00
|
|
|
NSString *foo = @"foo";
|
|
|
|
id caught = nil;
|
|
|
|
int final = 0;
|
|
|
|
int wrongCatch = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
@throw foo;
|
|
|
|
}
|
|
|
|
catch (void *foo)
|
|
|
|
{
|
|
|
|
wrongCatch = 1;
|
|
|
|
}
|
|
|
|
catch (NSString *f)
|
|
|
|
{
|
|
|
|
caught = f;
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
final = 1;
|
|
|
|
}
|
|
|
|
PASS(0==final, "catchall not used to catch object");
|
|
|
|
PASS(0==wrongCatch, "Incorrect object catch not used to catch object");
|
|
|
|
PASS(caught == foo, "Unified exception model works correctly");
|
2011-03-28 13:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-03-28 13:57:27 +00:00
|
|
|
#endif
|
|
|
|
|
2011-03-28 13:22:57 +00:00
|
|
|
#else
|
|
|
|
int main(void)
|
|
|
|
{
|
2011-03-22 19:47:10 +00:00
|
|
|
return 0;
|
2011-03-21 11:52:30 +00:00
|
|
|
}
|
|
|
|
#endif
|