Skip to content

Commit

Permalink
Fix #604 - add test of template results
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lcartey committed Sep 25, 2024
1 parent 61cd6ca commit aca6d40
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cpp/common/test/rules/deadcode/DeadCode.expected
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
| test.cpp:85:3:85:43 | declaration | This statement is dead code. |
| test.cpp:87:3:87:30 | declaration | This statement is dead code. |
| test.cpp:90:3:90:50 | declaration | This statement is dead code. |
| test.cpp:108:3:108:21 | ExprStmt | This statement is dead code. |
| test.cpp:120:3:120:23 | ExprStmt | This statement is dead code. |
28 changes: 28 additions & 0 deletions cpp/common/test/rules/deadcode/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,31 @@ int test_dead_code(int x) {

return live5 + live6 + constexpr_used_array[1]; // COMPLIANT
}

class Foo {
public:
void bar() { may_have_side_effects(); }
};

class Baz {
public:
void bar() {} // No side effects
};

template <typename T> void test_template() {
T t;
t.bar(); // COMPLIANT
no_side_effects(1); // NON_COMPLIANT
}

template <typename T> void test_unused_template() {
T t;
t.bar(); // COMPLIANT
no_side_effects(
1); // NON_COMPLIANT[FALSE_NEGATIVE] - unused templates are not extracted
}

void test() {
test_template<Foo>();
test_template<Baz>(); // NON_COMPLIANT - template call has no affect
}

0 comments on commit aca6d40

Please sign in to comment.