This behavior in the compiler seems intentional (and reasonable.)
If the -Wunused-value
warning were emitted for all ObjC message send expressions where the method has a return value that is implicitly discarded (i.e. there is no void cast,) it would be so “chatty” that it would render itself useless. In other words, people would get such large numbers of warnings for existing projects that they would simply turn the warning off, rather than annotate all such cases with (void)
casts.
The fact that the warning is emitted in the case where the return value is cast to BOOL
is a nice surprise, and makes sense: it's reasonable for the compiler to then assume that the programmer is indeed interested in the return value (because why otherwise include the cast?)
The Clang development community on the cfe-dev mailing list might be able to give you more information on the thinking behind this.
I don't know of any way to force the behavior you want in general, but for the interfaces in your own code you can force this warning by using the warn_unused_result
attribute in the ObjC method (or C function) declaration:
@interface MyClass : NSObject
- (int) myReturnValueMustNotBeIgnored __attribute__((warn_unused_result));
@end