bump product version to 5.0.4.1
[LibreOffice.git] / compilerplugins / clang / derefnullptr.cxx
blob83fa5c4a0b9144beb1ab445a23ddd2d74f482021
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(InstantiationData const & data): Plugin(data) {}
20 void run() override
21 { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
23 bool VisitUnaryDeref(UnaryOperator const * op);
26 bool DerefNullPtr::VisitUnaryDeref(UnaryOperator const * op) {
27 if (!ignoreLocation(op)
28 && (op->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
29 compiler.getASTContext(), Expr::NPC_ValueDependentIsNotNull/*TODO*/)
30 != Expr::NPCK_NotNull))
32 report(
33 DiagnosticsEngine::Warning, "null pointer dereference",
34 op->getLocStart())
35 << op->getSourceRange();
37 return true;
40 loplugin::Plugin::Registration<DerefNullPtr> X("derefnullptr");
44 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */