Skip to content

Commit aca6d40

Browse files
committed
Fix #604 - add test of template results
The modifications to the query to handle multiple copies of a statement across different targets also support reporting of issues across multiple template instantiations. This commit adds additional tests to demonstrate that this works effectively.
1 parent 61cd6ca commit aca6d40

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

cpp/common/test/rules/deadcode/DeadCode.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
| test.cpp:85:3:85:43 | declaration | This statement is dead code. |
1616
| test.cpp:87:3:87:30 | declaration | This statement is dead code. |
1717
| test.cpp:90:3:90:50 | declaration | This statement is dead code. |
18+
| test.cpp:108:3:108:21 | ExprStmt | This statement is dead code. |
19+
| test.cpp:120:3:120:23 | ExprStmt | This statement is dead code. |

cpp/common/test/rules/deadcode/test.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,31 @@ int test_dead_code(int x) {
9191

9292
return live5 + live6 + constexpr_used_array[1]; // COMPLIANT
9393
}
94+
95+
class Foo {
96+
public:
97+
void bar() { may_have_side_effects(); }
98+
};
99+
100+
class Baz {
101+
public:
102+
void bar() {} // No side effects
103+
};
104+
105+
template <typename T> void test_template() {
106+
T t;
107+
t.bar(); // COMPLIANT
108+
no_side_effects(1); // NON_COMPLIANT
109+
}
110+
111+
template <typename T> void test_unused_template() {
112+
T t;
113+
t.bar(); // COMPLIANT
114+
no_side_effects(
115+
1); // NON_COMPLIANT[FALSE_NEGATIVE] - unused templates are not extracted
116+
}
117+
118+
void test() {
119+
test_template<Foo>();
120+
test_template<Baz>(); // NON_COMPLIANT - template call has no affect
121+
}

0 commit comments

Comments
 (0)