Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d527dbe

Browse files
committed
CPP: Add test case.
1 parent d918cb1 commit d527dbe

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 82/AV Rule 82.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ struct TemplatedAssignmentBad {
201201
}
202202
};
203203

204+
template<class T>
205+
class Obj3 {
206+
public:
207+
Obj3<T> &subFunc(const Obj3<T> &other) {
208+
return *this;
209+
}
210+
211+
Obj3<T> &operator=(const Obj3<T> &other) {
212+
return subFunc(other); // GOOD (returns *this) [FALSE POSITIVE]
213+
}
214+
};
215+
204216
int main() {
205217
Container c;
206218
c = c;
@@ -211,5 +223,7 @@ int main() {
211223
taGood = 3;
212224
TemplatedAssignmentBad taBad;
213225
taBad = 4;
226+
Obj3<int> obj3_a, obj3_b;
227+
obj3_a = obj3_b;
214228
return 0;
215229
}

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 82/AV Rule 82.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
| AV Rule 82.cpp:63:29:63:29 | operator= | Assignment operator in class TemplateReturnAssignment<int> does not return a reference to *this. |
44
| AV Rule 82.cpp:63:29:63:37 | operator= | Assignment operator in class TemplateReturnAssignment<T> does not return a reference to *this. |
55
| AV Rule 82.cpp:199:52:199:52 | operator= | Assignment operator in class TemplatedAssignmentBad should have return type TemplatedAssignmentBad&. Otherwise a copy is created at each call. |
6+
| AV Rule 82.cpp:211:12:211:20 | operator= | Assignment operator in class Obj3<T> does not return a reference to *this. |

0 commit comments

Comments
 (0)