Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / compilerplugins / clang / privatebase.cxx
blob60acfc347ed9991f7147d9ab5653e4ea75229a33
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 PrivateBase:
15 public RecursiveASTVisitor<PrivateBase>, public loplugin::Plugin
17 public:
18 explicit PrivateBase(loplugin::InstantiationData const & data): Plugin(data)
21 void run() override;
23 bool VisitCXXRecordDecl(CXXRecordDecl const * decl);
26 void PrivateBase::run() {
27 if (compiler.getLangOpts().CPlusPlus) {
28 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
32 bool PrivateBase::VisitCXXRecordDecl(CXXRecordDecl const * decl) {
33 if (ignoreLocation(decl) || !decl->isThisDeclarationADefinition()
34 || decl->getTagKind() != TTK_Class)
36 return true;
38 for (auto i = decl->bases_begin(); i != decl->bases_end(); ++i) {
39 if (i->getAccessSpecifierAsWritten() == AS_none) {
40 report(
41 DiagnosticsEngine::Warning,
42 "base class is private by default; explicitly give an access"
43 " specifier",
44 i->getLocStart())
45 << i->getSourceRange();
48 return true;
51 loplugin::Plugin::Registration<PrivateBase> X("privatebase");
55 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */