aboutsummaryrefslogtreecommitdiffstats
path: root/src/checks/requiredresults.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/checks/requiredresults.cpp')
-rw-r--r--src/checks/requiredresults.cpp88
1 files changed, 42 insertions, 46 deletions
diff --git a/src/checks/requiredresults.cpp b/src/checks/requiredresults.cpp
index 220a4e42..e9a0f09b 100644
--- a/src/checks/requiredresults.cpp
+++ b/src/checks/requiredresults.cpp
@@ -24,7 +24,7 @@
#include "requiredresults.h"
#include "Utils.h"
-#include "checkmanager.h"
+
#include <clang/AST/DeclCXX.h>
#include <clang/AST/Expr.h>
@@ -37,50 +37,48 @@ RequiredResults::RequiredResults(const std::string &name, ClazyContext *context)
{
}
-bool RequiredResults::shouldIgnoreMethod(const std::string &qualifiedName)
+bool RequiredResults::shouldIgnoreMethod(const StringRef &qualifiedName)
{
- static std::vector<std::string> files;
- if (files.empty()) {
- files.reserve(31);
- files.push_back("QDir::mkdir");
- files.push_back("QDir::rmdir");
- files.push_back("QDir::mkpath");
- files.push_back("QDBusConnection::send");
-
- files.push_back("QRegExp::indexIn");
- files.push_back("QRegExp::exactMatch");
- files.push_back("QQmlProperty::write");
- files.push_back("QQmlProperty::reset");
- files.push_back("QWidget::winId");
- files.push_back("QtWaylandClient::QWaylandEglWindow::contentFBO");
- files.push_back("ProString::updatedHash");
+ static const std::vector<StringRef> files = {
+ "QDir::mkdir",
+ "QDir::rmdir",
+ "QDir::mkpath",
+ "QDBusConnection::send",
+
+ "QRegExp::indexIn",
+ "QRegExp::exactMatch",
+ "QQmlProperty::write",
+ "QQmlProperty::reset",
+ "QWidget::winId",
+ "QtWaylandClient::QWaylandEglWindow::contentFBO",
+ "ProString::updatedHash",
// kdepim
- files.push_back("KCalCore::Incidence::recurrence");
- files.push_back("KCalCore::RecurrenceRule::Private::buildCache");
- files.push_back("KAlarmCal::KAEvent::updateKCalEvent");
- files.push_back("Akonadi::Server::Collection::clearMimeTypes");
- files.push_back("Akonadi::Server::Collection::addMimeType");
- files.push_back("Akonadi::Server::PimItem::addFlag");
- files.push_back("Akonadi::Server::PimItem::addTag");
+ "KCalCore::Incidence::recurrence",
+ "KCalCore::RecurrenceRule::Private::buildCache",
+ "KAlarmCal::KAEvent::updateKCalEvent",
+ "Akonadi::Server::Collection::clearMimeTypes",
+ "Akonadi::Server::Collection::addMimeType",
+ "Akonadi::Server::PimItem::addFlag",
+ "Akonadi::Server::PimItem::addTag",
// kf5 libs
- files.push_back("KateVi::Command::execute");
- files.push_back("KArchiveDirectory::copyTo");
- files.push_back("KBookmarkManager::saveAs");
- files.push_back("KBookmarkManager::save");
- files.push_back("KLineEditPrivate::copySqueezedText");
- files.push_back("KJS::UString::Rep::hash");
- files.push_back("KCModuleProxy::realModule");
- files.push_back("KCategorizedView::visualRect");
- files.push_back("KateLineLayout::textLine");
- files.push_back("DOM::HTMLCollectionImpl::firstItem");
- files.push_back("DOM::HTMLCollectionImpl::nextItem");
- files.push_back("DOM::HTMLCollectionImpl::firstItem");
- files.push_back("ImapResourceBase::settings");
- }
-
- return clazy_std::contains(files, qualifiedName);
+ "KateVi::Command::execute",
+ "KArchiveDirectory::copyTo",
+ "KBookmarkManager::saveAs",
+ "KBookmarkManager::save",
+ "KLineEditPrivate::copySqueezedText",
+ "KJS::UString::Rep::hash",
+ "KCModuleProxy::realModule",
+ "KCategorizedView::visualRect",
+ "KateLineLayout::textLine",
+ "DOM::HTMLCollectionImpl::firstItem",
+ "DOM::HTMLCollectionImpl::nextItem",
+ "DOM::HTMLCollectionImpl::firstItem",
+ "ImapResourceBase::settings"
+ };
+
+ return clazy::contains(files, qualifiedName);
}
void RequiredResults::VisitStmt(clang::Stmt *stm)
@@ -94,12 +92,12 @@ void RequiredResults::VisitStmt(clang::Stmt *stm)
if (!callExpr)
continue;
- CXXMethodDecl *methodDecl = callExpr->getMethodDecl();
+ CXXMethodDecl *methodDecl = callExpr->getMethodDecl();
if (!methodDecl || !methodDecl->isConst())
continue;
std::string methodName = methodDecl->getQualifiedNameAsString();
- if (shouldIgnoreMethod(methodName)) // Filter out some false positives
+ if (shouldIgnoreMethod(StringRef(methodName.c_str()))) // Filter out some false positives
continue;
QualType qt = methodDecl->getReturnType();
@@ -118,7 +116,7 @@ void RequiredResults::VisitStmt(clang::Stmt *stm)
}
// qt.isConstQualified() not working !? TODO: Replace this string parsing when I figure it out
- if (type->isReferenceType() && !clazy_std::contains(qt.getAsString(), "const ")) {
+ if (type->isReferenceType() && !clazy::contains(qt.getAsString(), "const ")) {
bailout = true;
break;
}
@@ -126,9 +124,7 @@ void RequiredResults::VisitStmt(clang::Stmt *stm)
if (!bailout) {
std::string error = std::string("Unused result of const member (") + methodName + ')';
- emitWarning(callExpr->getLocStart(), error.c_str());
+ emitWarning(getLocStart(callExpr), error.c_str());
}
}
}
-
-// REGISTER_CHECK("unused-result", RequiredResults)