mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Tweaks to let comp[iler know that methods to raise an exception don't return.
This commit is contained in:
parent
cc97172bdd
commit
d8e7607582
4 changed files with 29 additions and 7 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2018-01-25 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/Foundation/NSException.h:
|
||||
* Source/NSException.m:
|
||||
* Source/Additions/NSObject+GNUstepBase.m:
|
||||
Mark exception raising methods with GS_NORETURN_METHOD.
|
||||
Alter noreturn method implementations so the compiler knows
|
||||
that they really don't return.
|
||||
Use pragma to suppress warnings abnout noreturn methods whose
|
||||
formal declaration says they return an id.
|
||||
|
||||
2018-01-23 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/Additions/NSNumber+GNUstepBase.m:
|
||||
|
|
|
@ -134,7 +134,8 @@ extern "C" {
|
|||
* <em>raised</em> using the -raise method.
|
||||
*/
|
||||
+ (void) raise: (NSString*)name
|
||||
format: (NSString*)format,... NS_FORMAT_FUNCTION(2,3);
|
||||
format: (NSString*)format,...
|
||||
NS_FORMAT_FUNCTION(2,3) GS_NORETURN_METHOD;
|
||||
|
||||
/**
|
||||
* Creates an exception with a name and a reason string using the
|
||||
|
@ -144,7 +145,8 @@ extern "C" {
|
|||
*/
|
||||
+ (void) raise: (NSString*)name
|
||||
format: (NSString*)format
|
||||
arguments: (va_list)argList NS_FORMAT_FUNCTION(2,0);
|
||||
arguments: (va_list)argList
|
||||
NS_FORMAT_FUNCTION(2,0) GS_NORETURN_METHOD;
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5,GS_API_LATEST) && GS_API_VERSION( 11501,GS_API_LATEST)
|
||||
/** Returns an array of the call stack return addresses at the point when
|
||||
|
@ -189,7 +191,7 @@ extern "C" {
|
|||
* NB. all other exception raising methods call this one, so if you
|
||||
* want to set a breakpoint when debugging, set it in this method.
|
||||
*/
|
||||
- (void) raise;
|
||||
- (void) raise GS_NORETURN_METHOD;
|
||||
|
||||
/** Returns the exception reason. */
|
||||
- (NSString*) reason;
|
||||
|
|
|
@ -31,6 +31,12 @@
|
|||
#import "GNUstepBase/NSDebug+GNUstepBase.h"
|
||||
#import "GNUstepBase/NSThread+GNUstepBase.h"
|
||||
|
||||
/* This file contains methods which nominally return an id but in fact
|
||||
* always rainse an exception and never return.
|
||||
* We need to suppress the compiler warning about that.
|
||||
*/
|
||||
#pragma GCC diagnostic ignored "-Wreturn-type"
|
||||
|
||||
/**
|
||||
* Extension methods for the NSObject class
|
||||
*/
|
||||
|
@ -42,7 +48,7 @@
|
|||
format: @"method %@ not implemented in %@(class)",
|
||||
selector ? (id)NSStringFromSelector(selector) : (id)@"(null)",
|
||||
NSStringFromClass(self)];
|
||||
return nil;
|
||||
while (0) ; // Does not return
|
||||
}
|
||||
|
||||
- (NSComparisonResult) compare: (id)anObject
|
||||
|
@ -106,7 +112,7 @@
|
|||
format: @"[%@%c%@] not implemented",
|
||||
NSStringFromClass([self class]), c,
|
||||
aSel ? (id)NSStringFromSelector(aSel) : (id)@"(null)"];
|
||||
return self; // Not reached
|
||||
while (0) ; // Does not return
|
||||
}
|
||||
|
||||
- (id) shouldNotImplement: (SEL)aSel
|
||||
|
@ -118,7 +124,7 @@
|
|||
format: @"[%@%c%@] should not be implemented",
|
||||
NSStringFromClass([self class]), c,
|
||||
aSel ? (id)NSStringFromSelector(aSel) : (id)@"(null)"];
|
||||
return self; // Not reached
|
||||
while (0) ; // Does not return
|
||||
}
|
||||
|
||||
- (id) subclassResponsibility: (SEL)aSel
|
||||
|
@ -129,7 +135,7 @@
|
|||
format: @"[%@%c%@] should be overridden by subclass",
|
||||
NSStringFromClass([self class]), c,
|
||||
aSel ? (id)NSStringFromSelector(aSel) : (id)@"(null)"];
|
||||
return self; // Not reached
|
||||
while (0) ; // Does not return
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1016,6 +1016,7 @@ callUncaughtHandler(id value)
|
|||
[self raise: name format: format arguments: args];
|
||||
// This probably doesn't matter, but va_end won't get called
|
||||
va_end(args);
|
||||
while (1); // does not return
|
||||
}
|
||||
|
||||
+ (void) raise: (NSString*)name
|
||||
|
@ -1028,6 +1029,7 @@ callUncaughtHandler(id value)
|
|||
reason = [NSString stringWithFormat: format arguments: argList];
|
||||
except = [self exceptionWithName: name reason: reason userInfo: nil];
|
||||
[except raise];
|
||||
while (1); // does not return
|
||||
}
|
||||
|
||||
/* For OSX compatibility -init returns nil.
|
||||
|
@ -1184,6 +1186,7 @@ callUncaughtHandler(id value)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
while (1); // does not return
|
||||
}
|
||||
|
||||
- (NSString*) name
|
||||
|
|
Loading…
Reference in a new issue