C++: FP test for "operator= doesn't return *this"

This rule should not apply to functions that never return.
This commit is contained in:
Jonas Jensen
2018-10-24 15:38:45 +02:00
parent 7affbe4a7d
commit 47a548f564
2 changed files with 24 additions and 0 deletions

View File

@@ -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;

View File

@@ -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. |