Merge pull request #413 from jbj/return-this-getblock

C++: Restore `exists(getBlock())` in AV Rule 82
This commit is contained in:
Geoffrey White
2018-11-06 17:04:05 +00:00
committed by GitHub
2 changed files with 11 additions and 0 deletions

View File

@@ -83,6 +83,7 @@ predicate assignOperatorWithWrongType(Operator op, string msg) {
predicate assignOperatorWithWrongResult(Operator op, string msg) {
op.hasName("operator=")
and not returnsDereferenceThis(op)
and exists(op.getBlock())
and not op.getType() instanceof VoidType
and not assignOperatorWithWrongType(op, _)
and msg = "Assignment operator in class " + op.getDeclaringType().getName() + " does not return a reference to *this."

View File

@@ -171,6 +171,16 @@ class Reachability {
static Reachability staticInstance;
};
class Forgivable {
// GOOD: wrong return type but that doesn't matter on a deleted function.
Forgivable operator=(const Forgivable &_val) = delete;
private:
// GOOD: wrong return type but that doesn't matter because this operator is
// private and probably also unimplemented, so no code can call it.
Forgivable operator=(int *_val);
};
int main() {
Container c;
c = c;