cid#1607171 Data race condition
[LibreOffice.git] / compilerplugins / clang / store / derivedclass.cxx
bloba1df0c253bdac2988d43c448cb0d8747e595aee0
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 DerivedClass:
15 public loplugin::FilteringPlugin<DerivedClass>
17 public:
18 explicit DerivedClass(InstantiationData const & data):
19 FilteringPlugin(data) {}
21 virtual void run() override
22 { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
24 bool VisitCXXRecordDecl(CXXRecordDecl const * decl);
27 bool BaseCheck(const CXXRecordDecl *BaseDefinition, void *BaseClassName) {
28 // print warning about deriving from this classes
29 // the name has to contain namespace, e.g. foo::bar::ClassName
30 const char *BaseClasses[] = {
31 "Dialog",
32 "ProgressBar",
33 "SfxToolBoxControl",
34 "StatusBar",
37 for (int i = 0; BaseClasses[i]; i++)
38 if (BaseDefinition->getQualifiedNameAsString().compare(BaseClasses[i]) == 0) {
39 *(const char **)BaseClassName = BaseClasses[i];
40 return false;
42 return true;
45 bool DerivedClass::VisitCXXRecordDecl(CXXRecordDecl const * decl) {
46 const char *BaseClassName = 0;
47 // checking for decl->hasDefinition() avoids crash in decl->forallBases
48 if (decl->hasDefinition() &&
49 // not sure what hasAnyDependentBases() does,
50 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
51 !decl->hasAnyDependentBases() &&
52 !decl->forallBases(BaseCheck, &BaseClassName)) {
53 string warning_msg("class %0 derives from ");
54 // no idea how BaseClassName can be 0 sometimes...
55 if (BaseClassName)
56 warning_msg += BaseClassName;
57 report(
58 DiagnosticsEngine::Warning,
59 warning_msg,
60 decl->getLocStart())
61 << decl->getQualifiedNameAsString() << decl->getSourceRange();
63 return true;
66 loplugin::Plugin::Registration<DerivedClass> X("derivedclass");
70 /* vim:set shiftwidth=4 softtabstop=4 tabstop=4 expandtab: */