yonran
yonran

Reputation: 19134

How to force “Expression result unused” warning to happen

When I compile a statement [[NSArray alloc] init];, clang gives “warning: expression result unused [-Wunused-value]”.

How do I cause “Expression result unused” warnings from my own function? For example:

@interface SimplePromise : NSObject
-(SimplePromise*)then:(id(^)(id result))block;
@end

-(void)someMethod {
    // I want this statement to cause a warning because
    // the transformed promise is dealloc’d before the block ever executes!
    [self.fetchPromise then:^id(id result) {
        self.fetchedData = result;
        return nil;
    }];
}

Upvotes: 3

Views: 564

Answers (1)

Greg Parker
Greg Parker

Reputation: 8012

Declare your method with __attribute__((warn_unused_result)):

-(SimplePromise*)then:(id(^)(id result))block  __attribute__((warn_unused_result));

Upvotes: 6

Related Questions