简体   繁体   中英

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;
    }];
}

__attribute__((warn_unused_result))声明您的方法:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM