Skip to content

Commit a8e929a

Browse files
committed
Changed based on review comments.
1 parent 310dc89 commit a8e929a

File tree

4 files changed

+11
-25
lines changed

4 files changed

+11
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
- `A0-1-3` - Considered use cases mentioned on issue [121](https://github.com/github/codeql-coding-standards/issues/121) while reporting a local function as "unused".
1+
- `A0-1-3` - Considered the following additional use cases while reporting a local function as "unused".
2+
- The address of a function is taken
3+
- The operand of an expression in an unevaluated context
4+
- Functions marked with [[maybe_unused]]
5+
- Explicitly deleted functions e.g. =delete
6+
- Use of any overload of a function in an overload set constitute a use of all members of the set. An overload set is a set of functions with the same name that differ in the number, type and/or qualifiers of their parameters.

cpp/autosar/src/rules/A0-1-3/UnusedLocalFunction.ql

+1-16
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,14 @@ import codingstandards.cpp.autosar
1919
import codingstandards.cpp.DynamicCallGraph
2020
import codingstandards.cpp.deadcode.UnusedFunctions
2121

22-
/** Checks if a function call exists to the function
23-
* passed in the arguments.
24-
*/
25-
predicate isCalled(Function unusedFunction) {
26-
unusedFunction = getTarget(_)
27-
}
2822

2923
/** Checks if an overloaded function of
3024
* the function passed in the arguments, is called.
3125
*/
3226
predicate overloadedFunctionIsCalled(Function unusedFunction) {
33-
exists (Function f | f = unusedFunction.getAnOverload() and isCalled(f))
34-
or
35-
unusedFunction.getNamespace().isAnonymous() and
36-
exists (TopLevelFunction overloadedFunction |
37-
overloadedFunction != unusedFunction and
38-
((overloadedFunction.getName() = unusedFunction.getName()) or
39-
(overloadedFunction.getQualifiedName() =
40-
unusedFunction.getQualifiedName()))
41-
)
27+
exists (Function f | f = unusedFunction.getAnOverload() and f = getTarget(_))
4228
}
4329

44-
4530
/** Checks if a Function's address was taken. */
4631
predicate addressBeenTaken(Function unusedFunction)
4732
{

cpp/autosar/test/rules/A0-1-3/test.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,6 @@ static int overload1(int c, int d) // COMPLAINT - overload1(int) is called.
121121
return c + d;
122122
}
123123

124-
namespace {
125-
int overload1(int c, float d) // COMPLAINT - overload1(int) is called.
126-
{
127-
return c + d;
128-
}
129-
} // namespace
130-
131124
int overload = overload1(5);
132125

133126
class classWithOverloads {

rule_packages/cpp/DeadCode.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@
6767
"tags": [
6868
"readability",
6969
"maintainability"
70-
]
70+
],
71+
"implementation_scope": {
72+
"description": "Functions defined in anonymous (unnamed) namespaces and global namespaces are not considered to be part of the same overload set."
73+
}
7174
}
7275
],
7376
"title": "Every function defined in an anonymous namespace, or static function with internal linkage, or private member function shall be used."

0 commit comments

Comments
 (0)