小编cze*_*boy的帖子

为什么Clang在没有return语句的块中被@try {}搞糊涂了?

在正常情况下,当声明一个块返回一个值,但return块中没有实际出现语句时,Clang无法编译它并返回错误(返回值丢失).

但是,当该块包含@try{} @catch(...){}或时,这会中断@try{} @finally{}.

有谁知道为什么?

我发现这个的方式就是当在ReactiveCocoa中使用@weakify()@strongify()进入RACExtScope时,在一个区块中我忘记返回一个信号.但编译器没有警告我并在运行时崩溃,这导致我深入研究它,预处理代码并发现它导致它.任何解释都会非常感激,老实说我不知道​​为什么会这样,谢谢!

我还创建了一个要点,以防有人发表评论/建议:https://gist.github.com/czechboy0/11358741

int main(int argc, const char * argv[])
{
    id (^iReturnStuff)() = ^id() {
        @try{} @finally{}
        //if you comment out line 4, Clang will not compile this.
        //if you leave it like this, Clang will compile and run this, even though
        //there's no value being returned.
        //is there something special in @try{} that turns off compiler errors?
    };
    return …
Run Code Online (Sandbox Code Playgroud)

objective-c clang objective-c-blocks

8
推荐指数
1
解决办法
444
查看次数

标签 统计

clang ×1

objective-c ×1

objective-c-blocks ×1