Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / compilerplugins / clang / derefnullptr.cxx
blob350bed2156dce89c5fabb2942d79c0fe2753d137
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "plugin.hxx"
12 namespace {
14 class DerefNullPtr:
15 public RecursiveASTVisitor<DerefNullPtr>, public loplugin::Plugin
17 public:
18 explicit DerefNullPtr(loplugin::InstantiationData const & data):
19 Plugin(data) {}
21 void run() override
22 { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
24 bool VisitUnaryDeref(UnaryOperator const * op);
27 bool DerefNullPtr::VisitUnaryDeref(UnaryOperator const * op) {
28 if (!ignoreLocation(op)
29 && (op->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
30 compiler.getASTContext(), Expr::NPC_ValueDependentIsNotNull/*TODO*/)
31 != Expr::NPCK_NotNull))
33 report(
34 DiagnosticsEngine::Warning, "null pointer dereference",
35 op->getLocStart())
36 << op->getSourceRange();
38 return true;
41 loplugin::Plugin::Registration<DerefNullPtr> X("derefnullptr");
45 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */