summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-06-13 17:53:53 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-06-13 17:54:38 +0200
commit5f500adec8a84e4a6455d9c24533dc96bdbdff20 (patch)
tree2f238c276e49675fa42d01af71874865b4a6b46c /compilerplugins
parentc21979a3279953ec28fc3d6e379b9a3ba98c4fd3 (diff)
loplugin:staticcall
Change-Id: Id46b391c09555c9ec30916fdd93b05455835d81b
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/staticcall.cxx49
1 files changed, 49 insertions, 0 deletions
diff --git a/compilerplugins/clang/staticcall.cxx b/compilerplugins/clang/staticcall.cxx
new file mode 100644
index 000000000000..8bbfcb6b38a8
--- /dev/null
+++ b/compilerplugins/clang/staticcall.cxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "plugin.hxx"
+
+namespace {
+
+class StaticCall:
+ public RecursiveASTVisitor<StaticCall>, public loplugin::Plugin
+{
+public:
+ explicit StaticCall(InstantiationData const & data): Plugin(data) {}
+
+ void run() override
+ { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
+
+ bool VisitCallExpr(CallExpr const * expr);
+};
+
+bool StaticCall::VisitCallExpr(CallExpr const * expr) {
+ if (ignoreLocation(expr)
+ || !isa<MemberExpr>(expr->getCallee()->IgnoreImpCasts()))
+ {
+ return true;
+ }
+ CXXMethodDecl const * decl = dyn_cast_or_null<CXXMethodDecl>(
+ expr->getDirectCallee());
+ if (decl != nullptr && decl->isStatic()) {
+ report(
+ DiagnosticsEngine::Warning,
+ ("calling static member function through member call syntax, use"
+ " '%0' instead"),
+ expr->getLocStart())
+ << decl->getQualifiedNameAsString() << expr->getSourceRange();
+ }
+ return true;
+}
+
+loplugin::Plugin::Registration<StaticCall> X("staticcall");
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */