__clang_analyzer__ 的重要性

Abh*_*nav 3 iphone xcode cocoa-touch objective-c ios

clang_analyzer的重要性是什么,因为如果不使用它,我会看到分析器在下面的代码中大喊泄漏。

#ifndef __clang_analyzer__
CGPathRef pathWithRoundRect(CGRect iRect, CGFloat iRadius) {
    CGMutablePathRef returnVal = CGPathCreateMutable();
    CGPathMoveToPoint();
    CGPathAddArcToPoint();
    CGPathAddArcToPoint();
    CGPathAddArcToPoint();
    CGPathAddArcToPoint();
    CGPathCloseSubpath(returnVal);
    return returnVal;
}
#endif
Run Code Online (Sandbox Code Playgroud)

Jos*_*ell 5

__clang_analyzer__是一个宏,在为分析器编译程序时定义(请参阅Clang 用户手册)。

定义后,#ifndef和 之间的代码#endif不会被编译,这意味着分析器看不到它,也无法告诉您CGMutablePath从名称不表明它返回的函数返回的拥有者。拥有参考。

您应该考虑添加create到函数名称的开头。