|
15 | 15 | import cpp |
16 | 16 | import codingstandards.cpp.misra |
17 | 17 |
|
18 | | -fromCastcast,TypesourceType,TypetargetType |
| 18 | +fromCastcast,TypesourceType,PointerTypetargetType,stringtypeKind |
19 | 19 | where |
20 | 20 | notisExcluded(cast, Conversions2Package::intToPointerCastProhibitedQuery())and |
21 | | -sourceType=cast.getExpr().getType().stripTopLevelSpecifiers()and |
22 | | -targetType=cast.getType().stripTopLevelSpecifiers()and |
23 | | -targetTypeinstanceofPointerTypeand |
24 | | -nottargetTypeinstanceofFunctionPointerTypeand |
25 | | -not( |
26 | | -// Exception: casts between void pointers are allowed |
27 | | -targetType.(PointerType).getBaseType().stripTopLevelSpecifiers()instanceofVoidTypeand |
28 | | -sourceTypeinstanceofPointerTypeand |
29 | | -sourceType.(PointerType).getBaseType().stripTopLevelSpecifiers()instanceofVoidType |
30 | | -)and |
| 21 | +sourceType=cast.getExpr().getType().getUnspecifiedType()and |
| 22 | +targetType=cast.getType().getUnspecifiedType()and |
31 | 23 | ( |
32 | 24 | // Integral types |
33 | | -sourceTypeinstanceofIntegralType |
| 25 | +sourceTypeinstanceofIntegralTypeand |
| 26 | +typeKind="integral" |
34 | 27 | or |
35 | 28 | // Enumerated types |
36 | | -sourceTypeinstanceofEnum |
| 29 | +sourceTypeinstanceofEnumand |
| 30 | +typeKind="enumerated" |
37 | 31 | or |
38 | 32 | // Pointer to void type |
39 | | -sourceTypeinstanceofPointerTypeand |
40 | | -sourceType.(PointerType).getBaseType().stripTopLevelSpecifiers()instanceofVoidType |
| 33 | +sourceType.(PointerType).getBaseType()instanceofVoidTypeand |
| 34 | +typeKind="pointer to void"and |
| 35 | +// Exception: casts between void pointers are allowed |
| 36 | +nottargetType.getBaseType()instanceofVoidType |
41 | 37 | ) |
42 | 38 | selectcast, |
43 | | -"Cast from '"+sourceType.toString()+"' to '"+targetType.toString()+"' is prohibited." |
| 39 | +"Cast from "+typeKind+" type '"+cast.getExpr().getType()+"' to pointer type '"+ |
| 40 | +cast.getType()+"'." |
0 commit comments