bump product version to 6.4.0.3
[LibreOffice.git] / compilerplugins / clang / derefnullptr.cxx
blob61ffbfab24dfb0fb7691931468eb9ac0a270518e
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 #ifndef LO_CLANG_SHARED_PLUGINS
12 #include "plugin.hxx"
14 namespace {
16 class DerefNullPtr:
17 public loplugin::FilteringPlugin<DerefNullPtr>
19 public:
20 explicit DerefNullPtr(loplugin::InstantiationData const & data):
21 FilteringPlugin(data) {}
23 void run() override
24 { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
26 bool VisitUnaryDeref(UnaryOperator const * op);
29 bool DerefNullPtr::VisitUnaryDeref(UnaryOperator const * op) {
30 if (!ignoreLocation(op)
31 && (op->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
32 compiler.getASTContext(), Expr::NPC_ValueDependentIsNotNull/*TODO*/)
33 != Expr::NPCK_NotNull))
35 report(
36 DiagnosticsEngine::Warning, "null pointer dereference",
37 compat::getBeginLoc(op))
38 << op->getSourceRange();
40 return true;
43 loplugin::Plugin::Registration<DerefNullPtr> derefnullptr("derefnullptr");
47 #endif // LO_CLANG_SHARED_PLUGINS
49 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */