Skip to content

Commit 8c28f1e

Browse files
committed
Added tests and generalized fix
1 parent 0f832d3 commit 8c28f1e

File tree

7 files changed

+50
-4
lines changed

7 files changed

+50
-4
lines changed

cpp/autosar/test/rules/M0-1-10.1/UnusedFunction.expected

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/M0-1-10/UnusedFunction.ql
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <cstdint>
2+
3+
namespace mains {
4+
static std::int32_t var;
5+
6+
// @brief namespace_func
7+
static void
8+
namespace_func(void) noexcept { // COMPLIANT: Called from "main" below.
9+
mains::var = -1;
10+
return;
11+
}
12+
} // namespace mains
13+
14+
std::int32_t func2() // COMPLIANT: Called from func1
15+
{
16+
return mains::var + 20;
17+
}
18+
19+
std::int32_t func1() { // COMPLIANT: Called from main
20+
return mains::var + func2(); // func2 called here.
21+
}
22+
23+
// @brief main
24+
// @return exit code
25+
std::int32_t main(void) {
26+
std::int32_t ret{0};
27+
try {
28+
ret = func1(); // func1 called here.
29+
mains::var += ret;
30+
} catch (...) {
31+
mains::namespace_func(); // namespace_func called here.
32+
}
33+
return ret;
34+
}

cpp/common/src/codingstandards/cpp/EncapsulatingFunctions.qll

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ abstract class EncapsulatingFunction extends Function { }
1414
class MainFunction extends MainLikeFunction {
1515
MainFunction() {
1616
hasGlobalName("main") and
17-
(
18-
getType() instanceof IntType or
19-
getType() instanceof Int32_t
20-
)
17+
getType().resolveTypedefs() instanceof IntType
2118
}
2219
}
2320

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.cpp:5:9:5:12 | main |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cpp
2+
import codingstandards.cpp.EncapsulatingFunctions
3+
4+
from MainFunction m
5+
select m
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
typedef signed int int32_t;
2+
3+
// @brief main
4+
// @return exit code
5+
int32_t main(void) {
6+
int32_t ret{0};
7+
return ret;
8+
}

0 commit comments

Comments
 (0)