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/.
16 #include "clang/AST/CXXInheritance.h"
18 // Check for final classes that have protected members
24 public loplugin::FilteringPlugin
<FinalProtected
>
27 explicit FinalProtected(loplugin::InstantiationData
const & data
):
28 FilteringPlugin(data
) {}
30 virtual void run() override
{
31 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
34 bool VisitCXXMethodDecl(CXXMethodDecl
const *);
35 bool VisitFieldDecl(FieldDecl
const *);
39 bool FinalProtected::VisitCXXMethodDecl(CXXMethodDecl
const * cxxMethodDecl
)
41 if (ignoreLocation(cxxMethodDecl
)) {
44 if (cxxMethodDecl
->getAccess() != AS_protected
) {
47 if (!cxxMethodDecl
->getParent()->hasAttr
<FinalAttr
>()) {
50 cxxMethodDecl
= cxxMethodDecl
->getCanonicalDecl();
51 report(DiagnosticsEngine::Warning
,
52 "final class should not have protected members - convert them to private",
53 compat::getBeginLoc(cxxMethodDecl
))
54 << cxxMethodDecl
->getSourceRange();
58 bool FinalProtected::VisitFieldDecl(FieldDecl
const * fieldDecl
)
60 if (ignoreLocation(fieldDecl
)) {
63 if (fieldDecl
->getAccess() != AS_protected
) {
66 if (!fieldDecl
->getParent()->hasAttr
<FinalAttr
>()) {
69 fieldDecl
= fieldDecl
->getCanonicalDecl();
70 report(DiagnosticsEngine::Warning
,
71 "final class should not have protected members - convert them to private",
72 compat::getBeginLoc(fieldDecl
))
73 << fieldDecl
->getSourceRange();
77 loplugin::Plugin::Registration
< FinalProtected
> X("finalprotected", true);
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */