1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #ifndef LO_CLANG_SHARED_PLUGINS
11 
12 #include "plugin.hxx"
13 
14 namespace {
15 
16 class PrivateBase:
17     public loplugin::FilteringPlugin<PrivateBase>
18 {
19 public:
PrivateBase(loplugin::InstantiationData const & data)20     explicit PrivateBase(loplugin::InstantiationData const & data): FilteringPlugin(data)
21     {}
22 
23     void run() override;
24 
25     bool VisitCXXRecordDecl(CXXRecordDecl const * decl);
26 };
27 
run()28 void PrivateBase::run() {
29     if (compiler.getLangOpts().CPlusPlus) {
30         TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
31     }
32 }
33 
VisitCXXRecordDecl(CXXRecordDecl const * decl)34 bool PrivateBase::VisitCXXRecordDecl(CXXRecordDecl const * decl) {
35     if (ignoreLocation(decl) || !decl->isThisDeclarationADefinition()
36         || decl->getTagKind() != TTK_Class)
37     {
38         return true;
39     }
40     for (auto i = decl->bases_begin(); i != decl->bases_end(); ++i) {
41         if (i->getAccessSpecifierAsWritten() == AS_none) {
42             report(
43                 DiagnosticsEngine::Warning,
44                 "base class is private by default; explicitly give an access"
45                     " specifier",
46                 compat::getBeginLoc(i))
47                 << i->getSourceRange();
48         }
49     }
50     return true;
51 }
52 
53 loplugin::Plugin::Registration<PrivateBase> privatebase("privatebase");
54 
55 }
56 
57 #endif // LO_CLANG_SHARED_PLUGINS
58 
59 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
60