File tree 2 files changed +27
-5
lines changed
cpp/common/test/rules/deadcode
2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change 15
15
| test.cpp:85:3:85:43 | declaration | This statement is dead code. |
16
16
| test.cpp:87:3:87:30 | declaration | This statement is dead code. |
17
17
| 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. |
18
+ | test.cpp:116:3:116:21 | ExprStmt | This statement is dead code. |
19
+ | test.cpp:117:3:117:27 | ExprStmt | This statement is dead code. |
20
+ | test.cpp:118:7:118:32 | ExprStmt | This statement is dead code. |
21
+ | test.cpp:139:3:139:35 | ExprStmt | This statement is dead code. |
Original file line number Diff line number Diff line change @@ -102,10 +102,27 @@ class Baz {
102
102
void bar () {} // No side effects
103
103
};
104
104
105
+ #define FULL_STMT_NO_SIDE_EFFECTS no_side_effects (1 );
106
+ #define PART_STMT_NO_SIDE_EFFECTS no_side_effects (1 )
107
+ #define BLOCK_SOME_SIDE_EFFECTS \
108
+ { \
109
+ may_have_side_effects (); \
110
+ no_side_effects (1 ); \
111
+ }
112
+
105
113
template <typename T> void test_template () {
106
114
T t;
107
- t.bar (); // COMPLIANT
108
- no_side_effects (1 ); // NON_COMPLIANT
115
+ t.bar (); // COMPLIANT
116
+ no_side_effects (1 ); // NON_COMPLIANT
117
+ FULL_STMT_NO_SIDE_EFFECTS // NON_COMPLIANT
118
+ PART_STMT_NO_SIDE_EFFECTS; // NON_COMPLIANT
119
+ BLOCK_SOME_SIDE_EFFECTS; // COMPLIANT - cannot determine loc for
120
+ // no_side_effects(1)
121
+ }
122
+
123
+ template <typename T> void test_variant_side_effects () {
124
+ T t;
125
+ t.bar (); // COMPLIANT - not dead in at least one instance
109
126
}
110
127
111
128
template <typename T> void test_unused_template () {
@@ -117,5 +134,8 @@ template <typename T> void test_unused_template() {
117
134
118
135
void test () {
119
136
test_template<Foo>();
120
- test_template<Baz>(); // NON_COMPLIANT - template call has no affect
137
+ test_template<Baz>();
138
+ test_variant_side_effects<Foo>(); // COMPLIANT
139
+ test_variant_side_effects<Baz>(); // NON_COMPLIANT - no effect in this
140
+ // instantiation
121
141
}
You can’t perform that action at this time.
0 commit comments