CPP: Add test case.

This commit is contained in:
Geoffrey White
2020-01-08 11:39:33 +00:00
parent d918cb1f6f
commit d527dbe47a
2 changed files with 15 additions and 0 deletions

View File

@@ -201,6 +201,18 @@ struct TemplatedAssignmentBad {
}
};
template<class T>
class Obj3 {
public:
Obj3<T> &subFunc(const Obj3<T> &other) {
return *this;
}
Obj3<T> &operator=(const Obj3<T> &other) {
return subFunc(other); // GOOD (returns *this) [FALSE POSITIVE]
}
};
int main() {
Container c;
c = c;
@@ -211,5 +223,7 @@ int main() {
taGood = 3;
TemplatedAssignmentBad taBad;
taBad = 4;
Obj3<int> obj3_a, obj3_b;
obj3_a = obj3_b;
return 0;
}

View File

@@ -3,3 +3,4 @@
| AV Rule 82.cpp:63:29:63:29 | operator= | Assignment operator in class TemplateReturnAssignment<int> does not return a reference to *this. |
| AV Rule 82.cpp:63:29:63:37 | operator= | Assignment operator in class TemplateReturnAssignment<T> does not return a reference to *this. |
| 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. |
| AV Rule 82.cpp:211:12:211:20 | operator= | Assignment operator in class Obj3<T> does not return a reference to *this. |