mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C++: Demonstrate FP in AV Rule 82
The added test is a reduced version of a FP observed in the wild.
This commit is contained in:
@@ -181,11 +181,35 @@ private:
|
|||||||
Forgivable operator=(int *_val);
|
Forgivable operator=(int *_val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This template has structure similar to `std::enable_if`.
|
||||||
|
template<typename S, typename T>
|
||||||
|
struct second {
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TemplatedAssignmentGood {
|
||||||
|
template<typename T>
|
||||||
|
typename second<T, TemplatedAssignmentGood &>::type operator=(T val) { // GOOD [FALSE POSITIVE]
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TemplatedAssignmentBad {
|
||||||
|
template<typename T>
|
||||||
|
typename second<T, TemplatedAssignmentBad>::type operator=(T val) { // BAD (missing &)
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Container c;
|
Container c;
|
||||||
c = c;
|
c = c;
|
||||||
TemplateReturnAssignment<int> tra(1);
|
TemplateReturnAssignment<int> tra(1);
|
||||||
tra = 2;
|
tra = 2;
|
||||||
tra = true;
|
tra = true;
|
||||||
|
TemplatedAssignmentGood taGood;
|
||||||
|
taGood = 3;
|
||||||
|
TemplatedAssignmentBad taBad;
|
||||||
|
taBad = 4;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,3 +2,6 @@
|
|||||||
| AV Rule 82.cpp:24:8:24:16 | operator= | Assignment operator in class Bad2 should have return type Bad2&. Otherwise a copy is created at each call. |
|
| AV Rule 82.cpp:24:8:24:16 | operator= | Assignment operator in class Bad2 should have return type Bad2&. Otherwise a copy is created at each call. |
|
||||||
| 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: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:63:29:63:37 | operator= | Assignment operator in class TemplateReturnAssignment<T> does not return a reference to *this. |
|
||||||
|
| AV Rule 82.cpp:192:55:192:63 | operator= | Assignment operator in class TemplatedAssignmentGood does not return a reference to *this. |
|
||||||
|
| AV Rule 82.cpp:199:52:199:52 | operator= | Assignment operator in class TemplatedAssignmentBad does not return a reference to *this. |
|
||||||
|
| AV Rule 82.cpp:199:52:199:60 | operator= | Assignment operator in class TemplatedAssignmentBad does not return a reference to *this. |
|
||||||
|
|||||||
Reference in New Issue
Block a user