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 loplugin::FilteringPlugin
<DerivedClass
>
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
[] = {
37 for (int i
= 0; BaseClasses
[i
]; i
++)
38 if (BaseDefinition
->getQualifiedNameAsString().compare(BaseClasses
[i
]) == 0) {
39 *(const char **)BaseClassName
= BaseClasses
[i
];
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...
56 warning_msg
+= BaseClassName
;
58 DiagnosticsEngine::Warning
,
61 << decl
->getQualifiedNameAsString() << decl
->getSourceRange();
66 loplugin::Plugin::Registration
<DerivedClass
> X("derivedclass");
70 /* vim:set shiftwidth=4 softtabstop=4 tabstop=4 expandtab: */