8

我无法让 clangc++-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 工作?Clang 的版本是 Ubuntu 11.10 上的 2.9。

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

4

1 回答 1

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.
于 2012-06-14T16:27:59.067 回答