8

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 Answer 1

7

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.
Sign up to request clarification or add additional context in comments.

2 Comments

What should it be set to? I tried setting it to 1 but still no worky. Google ain't turning up squat.
Is this answer still current?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.