|
16 | 16 |
|
17 | 17 | import cpp |
18 | 18 | import codingstandards.cpp.autosar |
19 | | -import codingstandards.cpp.Operator |
20 | | -import cpp |
| 19 | +import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared |
21 | 20 |
|
22 | | -/* |
23 | | - * This query performs a simple syntactic check to ensure that the return value of the function is |
24 | | - * not completely ignored. This matches the examples given in the rule, although the text itself is |
25 | | - * not entirely clear. This means it will not find cases where something is done with the return |
26 | | - * value, but it is not meaningfully read. For example: `int ret_val = f();`, with no subsequent |
27 | | - * access of `ret_val`. However, such a case _would_ be flagged by A0-1-1 - Useless assignment. |
28 | | - */ |
| 21 | +module UnusedReturnValueConfig implements UnusedReturnValueSharedConfigSig { |
| 22 | + Query getQuery() { result = DeadCodePackage::unusedReturnValueQuery() } |
| 23 | +} |
29 | 24 |
|
30 | | -from FunctionCall fc, Function f |
31 | | -where |
32 | | - not isExcluded(fc, DeadCodePackage::unusedReturnValueQuery()) and |
33 | | - // Find function calls in `ExprStmt`s, which indicate the return value is ignored |
34 | | - fc.getParent() instanceof ExprStmt and |
35 | | - // Ignore calls to void functions, which don't return values |
36 | | - not fc.getUnderlyingType() instanceof VoidType and |
37 | | - // Get the function target |
38 | | - f = fc.getTarget() and |
39 | | - // Overloaded (i.e. user defined) operators should behave in the same way as built-in operators, |
40 | | - // so the rule does not require the use of the return value |
41 | | - not f instanceof Operator and |
42 | | - // Exclude cases where the function call is generated within a macro, as the user of the macro is |
43 | | - // not necessarily able to address those results |
44 | | - not fc.isAffectedByMacro() and |
45 | | - // Rule allows disabling this rule where a static_cast<void> or a C-style cast to void is applied |
46 | | - not exists(Cast cast | cast instanceof StaticCast or cast instanceof CStyleCast | |
47 | | - fc.getExplicitlyConverted() = cast and |
48 | | - cast.getActualType() instanceof VoidType |
49 | | - ) |
50 | | -select fc, "Return value from call to $@ is unused.", f, f.getName() |
| 25 | +import UnusedReturnValueShared<UnusedReturnValueConfig> |
0 commit comments