簡體   English   中英

如何強制“表達結果未使用”警告發生

[英]How to force “Expression result unused” warning to happen

當我編譯一條語句[[NSArray alloc] init]; ,clang給出“警告:表達式結果未使用[-Wunused-value]”。

如何從我自己的函數中引起“表達式結果未使用”警告? 例如:

@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));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM