nss: upgrade to release 3.73
[LibreOffice.git] / compilerplugins / clang / finalprotected.cxx
blob41b994c049d5492c48b745026cc348ef069fa1ac
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 */
9 #ifndef LO_CLANG_SHARED_PLUGINS
11 #include <string>
12 #include <iostream>
13 #include <map>
14 #include <set>
16 #include "plugin.hxx"
17 #include "clang/AST/CXXInheritance.h"
19 // Check for final classes that have protected members
21 namespace
24 class FinalProtected:
25 public loplugin::FilteringPlugin<FinalProtected>
27 public:
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)) {
43 return true;
45 if (cxxMethodDecl->getAccess() != AS_protected) {
46 return true;
48 if (!cxxMethodDecl->getParent()->hasAttr<FinalAttr>()) {
49 return true;
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();
56 return true;
59 bool FinalProtected::VisitFieldDecl(FieldDecl const * fieldDecl)
61 if (ignoreLocation(fieldDecl)) {
62 return true;
64 if (fieldDecl->getAccess() != AS_protected) {
65 return true;
67 if (!fieldDecl->getParent()->hasAttr<FinalAttr>()) {
68 return true;
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();
75 return true;
78 loplugin::Plugin::Registration< FinalProtected > finalprotected("finalprotected");
80 } // namespace
82 #endif // LO_CLANG_SHARED_PLUGINS
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */