Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / weakobject.cxx
blob7f1a2986faa5c949f9d6879a6160f151a1d13c56
2 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /*
4 * This file is part of the LibreOffice project.
6 * Based on LLVM/Clang.
8 * This file is distributed under the University of Illinois Open Source
9 * License. See LICENSE.TXT for details.
12 #ifndef LO_CLANG_SHARED_PLUGINS
14 #include <cassert>
15 #include <string>
16 #include <iostream>
17 #include <fstream>
18 #include <set>
19 #include <unordered_set>
20 #include "plugin.hxx"
21 #include "check.hxx"
24 Check for places where we end up with more than one copy of cppu::OweakObject in a class, which
25 really should not happen - we should be using one of the AggImplInheritanceHelper classes then
26 to inherit.
29 namespace
31 class WeakObject : public loplugin::FilteringPlugin<WeakObject>
33 public:
34 explicit WeakObject(loplugin::InstantiationData const& data)
35 : FilteringPlugin(data)
39 virtual bool preRun() override
41 return true;
44 virtual void run() override
46 if (preRun())
47 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
50 bool VisitCXXRecordDecl( const CXXRecordDecl* decl);
54 bool WeakObject::VisitCXXRecordDecl(const CXXRecordDecl* decl)
56 if (ignoreLocation(decl))
57 return true;
58 if (!decl->hasDefinition())
59 return true;
60 if (decl->hasAnyDependentBases())
61 return true;
62 int cnt = 0;
63 decl->forallBases(
64 [&cnt] (const CXXRecordDecl *BaseDefinition) -> bool
66 if (loplugin::DeclCheck(BaseDefinition).Class("OWeakObject").Namespace("cppu").GlobalNamespace())
67 ++cnt;
68 return true;
69 });
70 if (cnt < 2)
71 return true;
73 report(DiagnosticsEngine::Warning, "more than one copy of cppu::OWeakObject inherited",
74 decl->getBeginLoc())
75 << decl->getSourceRange();
76 return true;
79 loplugin::Plugin::Registration<WeakObject> weakobject("weakobject", false);
81 } // namespace
83 #endif // LO_CLANG_SHARED_PLUGINS
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */