Skip to content

Commit 6239455

Browse files
committed
C++: Remove extra type check in AV Rule 82
These type checks were overlapping with `assignOperatorWithWrongType` is are no longer needed now that `assignOperatorWithWrongType` is improved. They were causing FPs and misleading error messages on uninstantiated templates.
1 parent 8ac427c commit 6239455

File tree

3 files changed

+1
-5
lines changed

3 files changed

+1
-5
lines changed

cpp/ql/src/jsf/4.10 Classes/AV Rule 82.ql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ predicate dereferenceThis(Expr e) {
5151
* This includes functions whose body is not in the database.
5252
*/
5353
predicate returnsPointerThis(Function f) {
54-
f.getType().getUnspecifiedType() instanceof PointerType and
5554
forall(ReturnStmt s | s.getEnclosingFunction() = f and reachable(s) |
5655
// `return this`
5756
pointerThis(s.getExpr())
@@ -64,7 +63,6 @@ predicate returnsPointerThis(Function f) {
6463
* database.
6564
*/
6665
predicate returnsDereferenceThis(Function f) {
67-
f.getType().getUnspecifiedType() instanceof ReferenceType and
6866
forall(ReturnStmt s | s.getEnclosingFunction() = f and reachable(s) |
6967
// `return *this`
7068
dereferenceThis(s.getExpr())

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 82/AV Rule 82.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ struct second {
189189

190190
struct TemplatedAssignmentGood {
191191
template<typename T>
192-
typename second<T, TemplatedAssignmentGood &>::type operator=(T val) { // GOOD [FALSE POSITIVE]
192+
typename second<T, TemplatedAssignmentGood &>::type operator=(T val) { // GOOD
193193
return *this;
194194
}
195195
};

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 82/AV Rule 82.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22
| 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. |
33
| AV Rule 82.cpp:63:29:63:29 | operator= | Assignment operator in class TemplateReturnAssignment<int> does not return a reference to *this. |
44
| AV Rule 82.cpp:63:29:63:37 | operator= | Assignment operator in class TemplateReturnAssignment<T> does not return a reference to *this. |
5-
| AV Rule 82.cpp:192:55:192:63 | operator= | Assignment operator in class TemplatedAssignmentGood does not return a reference to *this. |
65
| 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. |
7-
| AV Rule 82.cpp:199:52:199:60 | operator= | Assignment operator in class TemplatedAssignmentBad does not return a reference to *this. |

0 commit comments

Comments
 (0)