@@ -18,6 +18,16 @@ import cpp
18
18
import codingstandards.cpp.autosar
19
19
import semmle.code.cpp.dataflow.DataFlow
20
20
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
+
21
31
/*
22
32
* This query performs a simple syntactic check to ensure that the return value of the function is
23
33
* 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
26
36
* access of `ret_val`. However, such a case _would_ be flagged by A0-1-1 - Useless assignment.
27
37
*/
28
38
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