I have some lines of my code which returns an error from our static code analyzer.
This analyzer is programmed with clang, and the source code of the rule that is violated is quite simple :
// For each cast expression in the code
bool VisitCastExpr(CastExpr *castExpr){
string errorMsg;
string CastName = castExpr->getCastKindName();
// If cast is from pointer to everything different than an integer, add violation
if((castExpr->getCastKind() == CK_MemberPointerToBoolean)||(castExpr->getCastKind() == CK_PointerToBoolean)||(castExpr->getCastKind() == CK_CPointerToObjCPointerCast)||(castExpr->getCastKind() == CK_BlockPointerToObjCPointerCast)||(castExpr->getCastKind() == CK_AnyPointerToBlockPointerCast)){
errorMsg = "Forbidden cast "+CastName+" from pointer to non-integer type";
addViolation(castExpr,this,errorMsg);
}
return true;
}
So basically, it just adds a violation when some cast (implicit or explicit) is done from pointer to something different than integer.
Here is one of the expressions that returns an error :
if(st_parametre_embarque.qs_nom.contains("PAR")){.
st_parametre_embarque is just a structure, and the field qs_nom is a QString.
Method Qstring::contains() does return a boolean.
Here is the violation message yielded by the code analyzer :
Forbidden cast PointerToBoolean from pointer to non-integer type
So I really don't see where there could be any castExpr, moreover from pointer to boolean.
Before Qt5, QString::contains returned a QBool, not a bool. That value has to be converted to a bool somehow, and the static analyzer has decided it's an implicit cast. Try making an explicit comparison with a boolean constant (i.e. invoking operator==(QBool, bool)) and see if the static analyzer follows it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With