3

first i input the command :

clang -cc1 -analyzer-checker-help 

list all the available checkers as follow.

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
......................................

then i pick two(BoolAssignment and VirtualCall) to test,code as follow:

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
};

but nothing happen,what's wrong? this the command that i invoke the checkes

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

1 に答える 1