CPP: Fix for explicitly cast expressions.

This commit is contained in:
Geoffrey White
2018-11-14 19:10:30 +00:00
parent 5cddabb1fd
commit 3f428a8876
3 changed files with 5 additions and 6 deletions

View File

@@ -11,6 +11,6 @@ import cpp
// see MISRA Rule 5-3-2
from UnaryMinusExpr ume
where ume.getOperand().getUnderlyingType().(IntegralType).isUnsigned()
where ume.getOperand().getExplicitlyConverted().getUnderlyingType().(IntegralType).isUnsigned()
and not ume.getOperand() instanceof Literal
select ume, "The unary minus operator should not be applied to an unsigned expression."

View File

@@ -1,9 +1,8 @@
| test.c:6:6:6:8 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:9:7:9:9 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:12:7:12:9 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:18:7:18:14 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:16:6:16:21 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:19:7:19:23 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:20:7:20:21 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:22:8:22:11 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:23:8:23:11 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:24:6:24:7 | - ... | The unary minus operator should not be applied to an unsigned expression. |

View File

@@ -13,11 +13,11 @@ void f(int i, unsigned int ui, signed int si, TUI tui, volatile unsigned int vui
si = -si;
i = -(int)i;
i = -(unsigned int)i; // BAD [NOT DETECTED]
i = -(unsigned int)i; // BAD
i = -(signed int)i;
ui = -(int)ui; // [FALSE POSITIVE]
ui = -(int)ui;
ui = -(unsigned int)ui; // BAD
ui = -(signed int)ui; // [FALSE POSITIVE]
ui = -(signed int)ui;
tui = -tui; // BAD
vui = -vui; // BAD