2013-10-25 40 views
3

首先我輸入命令:一些鐺靜態分析器的棋子沒有linux下的工作

clang -cc1 -analyzer-checker-help 

列表中的所有可用的棋子如下。

alpha.core.BoolAssignment  Warn about assigning non-{0,1} values to Boolean variables 
    alpha.core.CastSize    Check when casting a malloc'ed type T, whether the size is a multiple of the size of T 
    alpha.core.CastToStruct   Check for cast from non-struct pointer to struct pointer 
    alpha.core.FixedAddr   Check for assignment of a fixed address to a pointer 
    alpha.core.PointerArithm  Check for pointer arithmetic on locations other than array elements 
    alpha.core.PointerSub   Check for pointer subtractions on two pointers pointing to different memory chunks 
    alpha.core.SizeofPtr   Warn about unintended use of sizeof() on pointer expressions 
    alpha.cplusplus.VirtualCall  Check virtual function calls during construction or destruction 
...................................... 

的話,我選兩個(BoolAssignment和VirtualCall)進行測試,代碼如下:

int f1(){ 
int a=5; 
short b=4; 
bool a1=a;//maybe warn 
bool b1=b;//maybe warn 
if(a1&&b1)return 1; 
return 0; 
} 
class M{ 
public: 
    virtual int GetAge(){return 0;} 
}; 
class P:public M{ 
public: 
    virtual int GetAge(){return 1;} 
    P(){GetAge();}//maybe warn 
    ~P(){GetAge();}//maybe warn 
}; 

,但沒有發生,有什麼不對? 這一點,我調用checkes命令

scan-build --use-analyzer=/usr/bin/clang clang++ test.cpp -c -o test.o 

回答

1

alpha.core.BoolAssignment不是在默認情況下的檢查。您必須使用-enable-checker選項啓用它。因此命令將是:

掃描構建--use分析器=的/ usr /斌/鐺-enable檢查工具 alpha.core.BoolAssignment鐺++ TEST.CPP -c -o test.o