aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2017-12-19 16:06:57 +0000
committerSergio Martins <iamsergio@gmail.com>2017-12-19 16:08:50 +0000
commitdeac882e9d882bd1c95e8e3f5b848c92022eba59 (patch)
treeb617c67c08a67889cd5d747ccd00362c4034d4fd /src
parenta7c06b5eaf88af38096c0f66f30c6f15a9e21bd1 (diff)
qdeleteall: Reword the warning message a bit
When you're using qDeleteAll(c.keys()) you should use qDeleteAll(c.keyBegin(), c.keyEnd()) The new messages are: warning: qDeleteAll() is being used on an unnecessary temporary container created by QMap::values(), use qDeleteAll(mycontainer) instead [-Wclazy-qdeleteall] warning: qDeleteAll() is being used on an unnecessary temporary container created by QMap::keys(), use qDeleteAll(mycontainer.keyBegin(), mycontainer.keyEnd()) instead [-Wclazy-qdeleteall] CCMAIL: aacid@kde.org
Diffstat (limited to 'src')
-rw-r--r--src/checks/level1/qdeleteall.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/checks/level1/qdeleteall.cpp b/src/checks/level1/qdeleteall.cpp
index 7c5a69e4..753d8667 100644
--- a/src/checks/level1/qdeleteall.cpp
+++ b/src/checks/level1/qdeleteall.cpp
@@ -37,12 +37,6 @@ QDeleteAll::QDeleteAll(const std::string &name, ClazyContext *context)
{
}
-static bool isInterestingMethod(const string &name)
-{
- static const vector<string> names = { "values", "keys" };
- return clazy_std::contains(names, name);
-}
-
void QDeleteAll::VisitStmt(clang::Stmt *stmt)
{
// Find a call to QMap/QSet/QHash::values/keys
@@ -52,7 +46,10 @@ void QDeleteAll::VisitStmt(clang::Stmt *stmt)
return;
const string funcName = func->getNameAsString();
- if (isInterestingMethod(funcName)) {
+ const bool isValues = funcName == "values";
+ const bool isKeys = isValues ? false : funcName == "keys";
+
+ if (isValues || isKeys) {
const std::string offendingClassName = offendingCall->getMethodDecl()->getParent()->getNameAsString();
if (QtUtils::isQtAssociativeContainer(offendingClassName)) {
// Once found see if the first parent call is qDeleteAll
@@ -63,9 +60,13 @@ void QDeleteAll::VisitStmt(clang::Stmt *stmt)
FunctionDecl *f = pc ? pc->getDirectCallee() : nullptr;
if (f) {
if (f->getNameAsString() == "qDeleteAll") {
- string msg = "Calling qDeleteAll with " + offendingClassName + "::" + funcName;
+ string msg = "qDeleteAll() is being used on an unnecessary temporary container created by " + offendingClassName + "::" + funcName + "()";
if (func->getNumParams() == 0) {
- msg += ", call qDeleteAll on the container itself";
+ if (isValues) {
+ msg += ", use qDeleteAll(mycontainer) instead";
+ } else {
+ msg += ", use qDeleteAll(mycontainer.keyBegin(), mycontainer.keyEnd()) instead";
+ }
}
emitWarning(p->getLocStart(), msg);