clang的scan-build不适用于简单的cpp文件

时间:2012-06-14 16:13:02

标签: c++ clang static-analysis

我无法让clang的c++-analyzer处理玩具C ++文件。

#include <iostream>

using namespace std;

int main()
{
    int t[4];
    int x,y;

    t[5]=1;
    if(x)
        y = 5;
    x = t[y];
}         

makefile只是

all: t.cpp
    $(CXX) t.cpp

scan-build make输出:

scan-build: 'clang' executable not found in '/usr/share/clang/scan-build/bin'.
scan-build: Using 'clang' from path: /usr/bin/clang
/usr/share/clang/scan-build/c++-analyzer t.cpp
scan-build: Removing directory '/tmp/scan-build-2012-06-14-6' because it contains no reports.

如何使c ++ - analyzer工作?在Ubuntu 11.10上,Clang的版本是2.9。

编辑:我知道代码不正确。关键是Clang并没有抱怨明显的错误。如果我将上面的代码粘贴到.c文件中(没有using ...)clang正确发出警告。

1 个答案:

答案 0 :(得分:7)

原因如下:

http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-September/011194.html

>>> When I run "clang --analyze" on my c++ source files individually I get reports,
>>> but none when using the scan-build tool.
>> 
>> This is intended behavior.  C++ support is still alpha and so it isn't enabled
>> by default in scan-build.  It's really only intended to be used by those
>> currently hacking on the analyzer.
>> 
>> If you want to enable C++ analysis, you must define the environment variable
>> CCC_ANALYZER_CPLUSPLUS.