是否可以禁止Xcode 4静态分析器警告?

| Xcode 4静态分析器在我的代码中报告了一些误报。有什么办法压制他们?     
已邀请:
我找到了一种解决方案:可以避免误报(例如Apple单例设计模式):
#ifndef __clang_analyzer__

// Code not to be analyzed

#endif
分析器将不会分析这些预处理程序指令之间的代码。     
看一下此页面,该页面显示了如何使用几个#define注释Objective-C的方法和参数,以帮助静态分析器(clang)做正确的事 http://clang-analyzer.llvm.org/annotations.html 从该页面:   Clang前端在中支持几个源代码级注释   GCC样式的属性和实用指示的形式,可以帮助您使用   Clang静态分析器更有用。这些注释都可以帮助   抑制误报并增强分析仪的能力   查找错误。     
在这里查看我的答案。您可以在文件中添加一个编译标志,静态分析器将忽略它们。对于您不关心的第三方代码,这对于您正在编写的第一方代码可能更好。     
在大多数情况下,使用CF_RETURNS_RETAINED之类的东西并遵循\'create \'规则对我有用,但是我遇到了无法抑制的情况。 最后,通过查看llvm源代码找到了一种抑制分析器的方法: https://llvm.org/svn/llvm-project/cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result   \“测试以查看是否在存储指向a的指针时是否抑制了错误   全球。\”
static CGLayerRef sSuppressStaticAnalyzer;
static CGLayerRef sDmxImg[2][2][1000]; // a cache of quartz drawings.
CGLayerRef CachedDmxImg(...) // which lives for lifetime of app!
{
    ...

    CGLayerRef img = sDmxImg[isDefault][leadingZeroes][dmxVal];
    if ( !img )
    {
        NSRect imgRect = <some cool rectangle>;

        [NSGraphicsContext saveGraphicsState];
        CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
        CGLayerRef cgLayerRef = CGLayerCreateWithContext(ctx, imgRect.size, NULL);
        CGContextRef layerCtx = CGLayerGetContext(cgLayerRef);
        [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort:layerCtx flipped:YES]];

        ... draw some gorgeous expensive Quartz stuff ...

        img = cgLayerRef;
        sDmxImg[isDefault][leadingZeroes][dmxVal] = cgLayerRef;
        sSuppressStaticAnalyzer = cgLayerRef; // suppress static analyzer warning!
        [NSGraphicsContext restoreGraphicsState];
   }
   return img;
}
由于某种原因,分配给静态数组并不能抑制警告,但是分配给普通的旧静态\'suppressStaticAnalyzer \'可以。 通过上述方法,使用CGLayerRef是我发现重新绘制缓存图像(除OpenGL之外)的最快方法。     

要回复问题请先登录注册