From bfe589d13fafc0801d709a79144114d289958cae Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Wed, 17 Nov 2021 10:04:35 +0100 Subject: remove loplugin:finalprotected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It just forces a custom rule that serves no real purpose. There's no technical difference. If one day a class gets inherited from then this information will be lost/incorrect. And mixing access on a virtual function is poor style. Change-Id: I0c27db8d694ad191a118d4e1d3d4a240e00456fd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125337 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- compilerplugins/clang/finalprotected.cxx | 84 -------------------------- compilerplugins/clang/store/finalprotected.cxx | 84 ++++++++++++++++++++++++++ compilerplugins/clang/test/finalprotected.cxx | 35 ----------- 3 files changed, 84 insertions(+), 119 deletions(-) delete mode 100644 compilerplugins/clang/finalprotected.cxx create mode 100644 compilerplugins/clang/store/finalprotected.cxx delete mode 100644 compilerplugins/clang/test/finalprotected.cxx (limited to 'compilerplugins') diff --git a/compilerplugins/clang/finalprotected.cxx b/compilerplugins/clang/finalprotected.cxx deleted file mode 100644 index 41b994c049d5..000000000000 --- a/compilerplugins/clang/finalprotected.cxx +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -#ifndef LO_CLANG_SHARED_PLUGINS - -#include -#include -#include -#include - -#include "plugin.hxx" -#include "clang/AST/CXXInheritance.h" - -// Check for final classes that have protected members - -namespace -{ - -class FinalProtected: - public loplugin::FilteringPlugin -{ -public: - explicit FinalProtected(loplugin::InstantiationData const & data): - FilteringPlugin(data) {} - - virtual void run() override { - TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); - } - - bool VisitCXXMethodDecl(CXXMethodDecl const *); - bool VisitFieldDecl(FieldDecl const *); -}; - - -bool FinalProtected::VisitCXXMethodDecl(CXXMethodDecl const * cxxMethodDecl) -{ - if (ignoreLocation(cxxMethodDecl)) { - return true; - } - if (cxxMethodDecl->getAccess() != AS_protected) { - return true; - } - if (!cxxMethodDecl->getParent()->hasAttr()) { - return true; - } - cxxMethodDecl = cxxMethodDecl->getCanonicalDecl(); - report(DiagnosticsEngine::Warning, - "final class should not have protected members - convert them to private", - compat::getBeginLoc(cxxMethodDecl)) - << cxxMethodDecl->getSourceRange(); - return true; -} - -bool FinalProtected::VisitFieldDecl(FieldDecl const * fieldDecl) -{ - if (ignoreLocation(fieldDecl)) { - return true; - } - if (fieldDecl->getAccess() != AS_protected) { - return true; - } - if (!fieldDecl->getParent()->hasAttr()) { - return true; - } - fieldDecl = fieldDecl->getCanonicalDecl(); - report(DiagnosticsEngine::Warning, - "final class should not have protected members - convert them to private", - compat::getBeginLoc(fieldDecl)) - << fieldDecl->getSourceRange(); - return true; -} - -loplugin::Plugin::Registration< FinalProtected > finalprotected("finalprotected"); - -} // namespace - -#endif // LO_CLANG_SHARED_PLUGINS - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/store/finalprotected.cxx b/compilerplugins/clang/store/finalprotected.cxx new file mode 100644 index 000000000000..41b994c049d5 --- /dev/null +++ b/compilerplugins/clang/store/finalprotected.cxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef LO_CLANG_SHARED_PLUGINS + +#include +#include +#include +#include + +#include "plugin.hxx" +#include "clang/AST/CXXInheritance.h" + +// Check for final classes that have protected members + +namespace +{ + +class FinalProtected: + public loplugin::FilteringPlugin +{ +public: + explicit FinalProtected(loplugin::InstantiationData const & data): + FilteringPlugin(data) {} + + virtual void run() override { + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + } + + bool VisitCXXMethodDecl(CXXMethodDecl const *); + bool VisitFieldDecl(FieldDecl const *); +}; + + +bool FinalProtected::VisitCXXMethodDecl(CXXMethodDecl const * cxxMethodDecl) +{ + if (ignoreLocation(cxxMethodDecl)) { + return true; + } + if (cxxMethodDecl->getAccess() != AS_protected) { + return true; + } + if (!cxxMethodDecl->getParent()->hasAttr()) { + return true; + } + cxxMethodDecl = cxxMethodDecl->getCanonicalDecl(); + report(DiagnosticsEngine::Warning, + "final class should not have protected members - convert them to private", + compat::getBeginLoc(cxxMethodDecl)) + << cxxMethodDecl->getSourceRange(); + return true; +} + +bool FinalProtected::VisitFieldDecl(FieldDecl const * fieldDecl) +{ + if (ignoreLocation(fieldDecl)) { + return true; + } + if (fieldDecl->getAccess() != AS_protected) { + return true; + } + if (!fieldDecl->getParent()->hasAttr()) { + return true; + } + fieldDecl = fieldDecl->getCanonicalDecl(); + report(DiagnosticsEngine::Warning, + "final class should not have protected members - convert them to private", + compat::getBeginLoc(fieldDecl)) + << fieldDecl->getSourceRange(); + return true; +} + +loplugin::Plugin::Registration< FinalProtected > finalprotected("finalprotected"); + +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/test/finalprotected.cxx b/compilerplugins/clang/test/finalprotected.cxx deleted file mode 100644 index c15564874447..000000000000 --- a/compilerplugins/clang/test/finalprotected.cxx +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - - -class S final { -protected: - void f(int f) { f1 = f; } // expected-error {{final class should not have protected members - convert them to private [loplugin:finalprotected]}} - int f1; // expected-error {{final class should not have protected members - convert them to private [loplugin:finalprotected]}} -public: - void g(); - int g1; -private: - void h(); - int h1; -}; - -class S2 { -protected: - void f(int f) { f1 = f; } - int f1; -public: - void g(); - int g1; -private: - void h(); - int h1; -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit