Skip to content

Commit 1ca6789

Browse files
Update deviations tests, which copy A0-1-2
1 parent c38153a commit 1ca6789

File tree

3 files changed

+18
-78
lines changed

3 files changed

+18
-78
lines changed
Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @id cpp/autosar/unused-return-value
2+
* @id cpp/autosar/unused-return-value-autosar
33
* @name A0-1-2: Unused return value
44
* @description The value returned by a function having a non-void return type that is not an
55
* overloaded operator shall be used.
@@ -17,31 +17,11 @@
1717
import cpp
1818
import codingstandards.cpp.CodingStandards
1919
import codingstandards.cpp.exclusions.cpp.RuleMetadata
20+
import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue
2021

2122
/* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */
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-
*/
23+
module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig {
24+
Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() }
25+
}
2926

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.getType() 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 thoes results
44-
not fc.isAffectedByMacro() and
45-
// Rule allows disabling this rule where a static_cast<void> is applied
46-
not fc.getExplicitlyConverted().(StaticCast).getActualType() instanceof VoidType
47-
select fc, "Return value from call to $@ is unused.", f, f.getName()
27+
import UnusedReturnValue<UnusedReturnValueAutosarConfig>
Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @id cpp/autosar/unused-return-value
2+
* @id cpp/autosar/unused-return-value-autosar
33
* @name A0-1-2: Unused return value
44
* @description The value returned by a function having a non-void return type that is not an
55
* overloaded operator shall be used.
@@ -17,31 +17,11 @@
1717
import cpp
1818
import codingstandards.cpp.CodingStandards
1919
import codingstandards.cpp.exclusions.cpp.RuleMetadata
20+
import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue
2021

2122
/* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */
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-
*/
23+
module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig {
24+
Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() }
25+
}
2926

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.getType() 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 thoes results
44-
not fc.isAffectedByMacro() and
45-
// Rule allows disabling this rule where a static_cast<void> is applied
46-
not fc.getExplicitlyConverted().(StaticCast).getActualType() instanceof VoidType
47-
select fc, "Return value from call to $@ is unused.", f, f.getName()
27+
import UnusedReturnValue<UnusedReturnValueAutosarConfig>
Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @id cpp/autosar/unused-return-value
2+
* @id cpp/autosar/unused-return-value-autosar
33
* @name A0-1-2: Unused return value
44
* @description The value returned by a function having a non-void return type that is not an
55
* overloaded operator shall be used.
@@ -17,31 +17,11 @@
1717
import cpp
1818
import codingstandards.cpp.CodingStandards
1919
import codingstandards.cpp.exclusions.cpp.RuleMetadata
20+
import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue
2021

2122
/* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */
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-
*/
23+
module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig {
24+
Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() }
25+
}
2926

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.getType() 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 thoes results
44-
not fc.isAffectedByMacro() and
45-
// Rule allows disabling this rule where a static_cast<void> is applied
46-
not fc.getExplicitlyConverted().(StaticCast).getActualType() instanceof VoidType
47-
select fc, "Return value from call to $@ is unused.", f, f.getName()
27+
import UnusedReturnValue<UnusedReturnValueAutosarConfig>

0 commit comments

Comments
 (0)