1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
15 public RecursiveASTVisitor
<DerivedClass
>,
16 public loplugin::Plugin
19 explicit DerivedClass(InstantiationData
const & data
):
22 virtual void run() override
23 { TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl()); }
25 bool VisitCXXRecordDecl(CXXRecordDecl
const * decl
);
28 bool BaseCheck(const CXXRecordDecl
*BaseDefinition
, void *BaseClassName
) {
29 // print warning about deriving from this classes
30 // the name has to contain namespace, e.g. foo::bar::ClassName
31 const char *BaseClasses
[] = {
38 for (int i
= 0; BaseClasses
[i
]; i
++)
39 if (BaseDefinition
->getQualifiedNameAsString().compare(BaseClasses
[i
]) == 0) {
40 *(const char **)BaseClassName
= BaseClasses
[i
];
46 bool DerivedClass::VisitCXXRecordDecl(CXXRecordDecl
const * decl
) {
47 const char *BaseClassName
= 0;
48 // checking for decl->hasDefinition() avoids crash in decl->forallBases
49 if (decl
->hasDefinition() &&
50 // not sure what hasAnyDependentBases() does,
51 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
52 !decl
->hasAnyDependentBases() &&
53 !decl
->forallBases(BaseCheck
, &BaseClassName
)) {
54 string
warning_msg("class %0 derives from ");
55 // no idea how BaseClassName can be 0 sometimes..
57 warning_msg
+= BaseClassName
;
59 DiagnosticsEngine::Warning
,
62 << decl
->getQualifiedNameAsString() << decl
->getSourceRange();
67 loplugin::Plugin::Registration
<DerivedClass
> X("derivedclass");
71 /* vim:set shiftwidth=4 softtabstop=4 tabstop=4 expandtab: */