|
16 | 16 |
|
17 | 17 | import cpp |
18 | 18 | import codingstandards.cpp.autosar |
19 | | -import semmle.code.cpp.dataflow.DataFlow |
20 | | - |
21 | | -predicate isStdIgnore(Element element) { |
22 | | - exists(NameQualifier nq | |
23 | | - nq.getQualifiedElement().toString() = "ignore" and |
24 | | - nq.toString() = "std::" and |
25 | | - element.toString() = "ignore" |
26 | | - ) |
27 | | -} |
28 | | - |
29 | | -/* The statement std::ignore = f() is not recognized an assignment; therefore, we do some painful gymnastics. */ |
30 | | -predicate isAssignment(FunctionCall assignment) { |
31 | | - exists(Operator operator | |
32 | | - assignment.getTarget() = operator and |
33 | | - operator.getName() = "operator=" and |
34 | | - // check if this is indeed an operator for assignment by checking if there are no overloads |
35 | | - not exists(operator.getAnOverload()) |
36 | | - ) |
37 | | -} |
38 | | - |
39 | | -predicate isAssignmentOperand(Expr operand) { |
40 | | - exists(FunctionCall assignment | isAssignment(assignment) and operand = assignment.getAChild()) |
41 | | -} |
| 19 | +import codingstandards.cpp.Operator |
| 20 | +import cpp |
42 | 21 |
|
43 | | -predicate returnValueIsAssignedToStdIgnore(FunctionCall fc) { |
44 | | - isAssignmentOperand(fc) and exists(Element stdIgnore | isStdIgnore(stdIgnore)) |
| 22 | +class StdIgnoreVariable extends NamespaceVariable { |
| 23 | + StdIgnoreVariable() { |
| 24 | + this.hasName("ignore") and |
| 25 | + this.getNamespace() instanceof StdNamespace |
| 26 | + } |
45 | 27 | } |
46 | 28 |
|
47 | 29 | /* |
|
77 | 59 | cast.getActualType() instanceof VoidType |
78 | 60 | ) |
79 | 61 | ) and |
80 | | - not returnValueIsAssignedToStdIgnore(fc) |
| 62 | + // Exclude assignments to std::ignore. |
| 63 | + not ( |
| 64 | + fc.getTarget() instanceof AssignmentOperator and |
| 65 | + fc.getAChild().(VariableAccess).getTarget() instanceof StdIgnoreVariable |
| 66 | + ) |
81 | 67 | select fc, "Return value from call to $@ is unused.", f, f.getName() |
0 commit comments