Skip to content

Commit aca8fdc

Browse files
committed
checkpoint: A0-1-2
1 parent 47805d8 commit aca8fdc

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ import cpp
1818
import codingstandards.cpp.autosar
1919
import semmle.code.cpp.dataflow.DataFlow
2020

21+
// Type isEdgeCase(Expr expr) {
22+
// // 1. c-style casts to void.
23+
// expr.(CStyleCast).getUnderlyingType()
24+
// // 2. Assignment to std::ignore
25+
// }
26+
27+
from CStyleCast expr
28+
where any()
29+
select expr, expr.getType()
30+
2131
/*
2232
* This query performs a simple syntactic check to ensure that the return value of the function is
2333
* not completely ignored. This matches the examples given in the rule, although the text itself is
@@ -26,21 +36,21 @@ import semmle.code.cpp.dataflow.DataFlow
2636
* access of `ret_val`. However, such a case _would_ be flagged by A0-1-1 - Useless assignment.
2737
*/
2838

29-
from FunctionCall fc, Function f
30-
where
31-
not isExcluded(fc, DeadCodePackage::unusedReturnValueQuery()) and
32-
// Find function calls in `ExprStmt`s, which indicate the return value is ignored
33-
fc.getParent() instanceof ExprStmt and
34-
// Ignore calls to void functions, which don't return values
35-
not fc.getUnderlyingType() instanceof VoidType and
36-
// Get the function target
37-
f = fc.getTarget() and
38-
// Overloaded (i.e. user defined) operators should behave in the same way as built-in operators,
39-
// so the rule does not require the use of the return value
40-
not f instanceof Operator and
41-
// Exclude cases where the function call is generated within a macro, as the user of the macro is
42-
// not necessarily able to address thoes results
43-
not fc.isAffectedByMacro() and
44-
// Rule allows disabling this rule where a static_cast<void> is applied
45-
not fc.getExplicitlyConverted().(StaticCast).getActualType() instanceof VoidType
46-
select fc, "Return value from call to $@ is unused.", f, f.getName()
39+
// from FunctionCall fc, Function f
40+
// where
41+
// not isExcluded(fc, DeadCodePackage::unusedReturnValueQuery()) and
42+
// // Find function calls in `ExprStmt`s, which indicate the return value is ignored
43+
// fc.getParent() instanceof ExprStmt and
44+
// // Ignore calls to void functions, which don't return values
45+
// not fc.getUnderlyingType() instanceof VoidType and
46+
// // Get the function target
47+
// f = fc.getTarget() and
48+
// // Overloaded (i.e. user defined) operators should behave in the same way as built-in operators,
49+
// // so the rule does not require the use of the return value
50+
// not f instanceof Operator and
51+
// // Exclude cases where the function call is generated within a macro, as the user of the macro is
52+
// // not necessarily able to address thoes results
53+
// not fc.isAffectedByMacro() and
54+
// // Rule allows disabling this rule where a static_cast<void> is applied
55+
// not fc.getExplicitlyConverted().(StaticCast).getActualType() instanceof VoidType
56+
// select fc, "Return value from call to $@ is unused.", f, f.getName()

0 commit comments

Comments
 (0)