mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
C++: FP test for "operator= doesn't return *this"
This rule should not apply to functions that never return.
This commit is contained in:
@@ -112,6 +112,28 @@ private:
|
||||
int val;
|
||||
};
|
||||
|
||||
struct Exception {
|
||||
virtual ~Exception();
|
||||
};
|
||||
|
||||
class AlwaysThrows {
|
||||
public:
|
||||
AlwaysThrows &operator=(int _val) { // GOOD [FALSE POSITIVE]
|
||||
throw Exception();
|
||||
// No `return` statement is generated by the C++ front end because it can
|
||||
// statically see that the end of the function is unreachable.
|
||||
}
|
||||
|
||||
AlwaysThrows &operator=(int *_val) { // GOOD [FALSE POSITIVE]
|
||||
int one = 1;
|
||||
if (one)
|
||||
throw Exception();
|
||||
// A `return` statement is generated by the C++ front end, but the
|
||||
// control-flow pruning in QL will establish that this is unreachable.
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
Container c;
|
||||
c = c;
|
||||
|
||||
@@ -2,3 +2,5 @@
|
||||
| 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: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<int> does not return a reference to *this. |
|
||||
| AV Rule 82.cpp:121:17:121:25 | operator= | Assignment operator in class AlwaysThrows does not return a reference to *this. |
|
||||
| AV Rule 82.cpp:127:17:127:25 | operator= | Assignment operator in class AlwaysThrows does not return a reference to *this. |
|
||||
|
||||
Reference in New Issue
Block a user