|
| 1 | +/** |
| 2 | + * @id c/misra/implicit-conversion-of-composite-expression |
| 3 | + * @name RULE-10-7: If a composite expression is used as one operand of an operator in which the usual arithmetic |
| 4 | + * @description If a composite expression is used as one operand of an operator in which the usual |
| 5 | + * arithmetic conversions are performed then the other operand shall not have wider |
| 6 | + * essential type |
| 7 | + * @kind problem |
| 8 | + * @precision very-high |
| 9 | + * @problem.severity error |
| 10 | + * @tags external/misra/id/rule-10-7 |
| 11 | + * external/misra/obligation/required |
| 12 | + */ |
| 13 | + |
| 14 | +import cpp |
| 15 | +import codingstandards.c.misra |
| 16 | +import codingstandards.c.misra.EssentialTypes |
| 17 | +import codingstandards.c.misra.MisraExpressions |
| 18 | + |
| 19 | +from |
| 20 | + OperationWithUsualArithmeticConversions arith, CompositeExpression compositeOp, Expr otherOp, |
| 21 | + Type compositeEssentialType, Type otherOpEssentialType |
| 22 | +where |
| 23 | + not isExcluded(arith, EssentialTypesPackage::implicitConversionOfCompositeExpressionQuery()) and |
| 24 | + arith.getAnOperand() = compositeOp and |
| 25 | + arith.getAnOperand() = otherOp and |
| 26 | + not otherOp = compositeOp and |
| 27 | + compositeEssentialType = getEssentialType(compositeOp) and |
| 28 | + otherOpEssentialType = getEssentialType(otherOp) and |
| 29 | + compositeEssentialType.getSize() < otherOpEssentialType.getSize() and |
| 30 | + // Operands of a different type category in an operation with the usual arithmetic conversions is |
| 31 | + // prohibited by Rule 10.4, so we only report cases here where the essential type categories are |
| 32 | + // the same |
| 33 | + getEssentialTypeCategory(compositeEssentialType) = getEssentialTypeCategory(otherOpEssentialType) |
| 34 | +select arith, |
| 35 | + "Implicit conversion of $@ from " + compositeEssentialType + " to " + otherOpEssentialType, |
| 36 | + compositeOp, "composite op" |
0 commit comments