Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 559
user1367401 Avatar asked Jun 14 '12 16:06

user1367401


1 Answers

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.
like image 78
user1367401 Avatar answered Nov 11 '22 23:11

user1367401