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/.
9 #ifndef LO_CLANG_SHARED_PLUGINS
17 #include "clang/AST/CXXInheritance.h"
19 // Check for final classes that have protected members
25 public loplugin::FilteringPlugin
<FinalProtected
>
28 explicit FinalProtected(loplugin::InstantiationData
const & data
):
29 FilteringPlugin(data
) {}
31 virtual void run() override
{
32 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
35 bool VisitCXXMethodDecl(CXXMethodDecl
const *);
36 bool VisitFieldDecl(FieldDecl
const *);
40 bool FinalProtected::VisitCXXMethodDecl(CXXMethodDecl
const * cxxMethodDecl
)
42 if (ignoreLocation(cxxMethodDecl
)) {
45 if (cxxMethodDecl
->getAccess() != AS_protected
) {
48 if (!cxxMethodDecl
->getParent()->hasAttr
<FinalAttr
>()) {
51 cxxMethodDecl
= cxxMethodDecl
->getCanonicalDecl();
52 report(DiagnosticsEngine::Warning
,
53 "final class should not have protected members - convert them to private",
54 compat::getBeginLoc(cxxMethodDecl
))
55 << cxxMethodDecl
->getSourceRange();
59 bool FinalProtected::VisitFieldDecl(FieldDecl
const * fieldDecl
)
61 if (ignoreLocation(fieldDecl
)) {
64 if (fieldDecl
->getAccess() != AS_protected
) {
67 if (!fieldDecl
->getParent()->hasAttr
<FinalAttr
>()) {
70 fieldDecl
= fieldDecl
->getCanonicalDecl();
71 report(DiagnosticsEngine::Warning
,
72 "final class should not have protected members - convert them to private",
73 compat::getBeginLoc(fieldDecl
))
74 << fieldDecl
->getSourceRange();
78 loplugin::Plugin::Registration
< FinalProtected
> finalprotected("finalprotected");
82 #endif // LO_CLANG_SHARED_PLUGINS
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */