Skip to content

Commit

Permalink
Fix false positive in qdatetime-utc
Browse files Browse the repository at this point in the history
QDateTime::currentDateTimeUtc().addYears(1).toMSecsSinceEpoch()
cannot be changed to use QDateTime::currentMSecsSinceEpoch()
  • Loading branch information
dfaure committed Feb 2, 2024
1 parent 92de308 commit 7ff2b2d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/checks/level0/qdatetime-utc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void QDateTimeUtc::VisitStmt(clang::Stmt *stmt)
}

std::vector<CallExpr *> chainedCalls = Utils::callListForChain(secondCall);
if (chainedCalls.size() < 2) {
if (chainedCalls.size() != 2) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions tests/qdatetime-utc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ void test()
QDateTime::currentDateTimeUtc().toMSecsSinceEpoch(); // Warning, this may even be improved!
QDateTime::currentDateTime().toSecsSinceEpoch(); // Warning
QDateTime::currentDateTimeUtc().toSecsSinceEpoch(); // Warning, this may even be improved!
QDateTime::currentDateTimeUtc().addYears(1).toMSecsSinceEpoch();
}
1 change: 1 addition & 0 deletions tests/qdatetime-utc/main.cpp.fixed.expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ void test()
QDateTime::currentMSecsSinceEpoch(); // Warning, this may even be improved!
QDateTime::currentSecsSinceEpoch(); // Warning
QDateTime::currentSecsSinceEpoch(); // Warning, this may even be improved!
QDateTime::currentDateTimeUtc().addYears(1).toMSecsSinceEpoch();
}

0 comments on commit 7ff2b2d

Please sign in to comment.