clang's scan-build doesn't work for simple cpp file

最后都变了- 提交于 2019-12-21 04:16:09

问题


I can't get clang's c++-analyzer to work on a toy C++ file.

#include <iostream>

using namespace std;

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

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

makefile is just

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

scan-build make output:

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.

How to make c++-analyzer work? Clang's version is 2.9 on Ubuntu 11.10.

EDIT: I'm aware the code is incorrect. The point is that Clang does not complain about the obvious bugs. If I paste the above code to a .c file (without the using ...) clang correctly emits warnings.


回答1:


Here's the reason:

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.


来源:https://stackoverflow.com/questions/11037139/clangs-scan-build-doesnt-work-for-simple-cpp-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!