Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / compilerplugins / clang / inlinevisible.cxx
blob6f0b638561787fe7df0badaf57222f4263ea5a9a
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 <cassert>
11 #include <string>
13 #include "clang/AST/Attr.h"
14 #include "clang/Sema/SemaInternal.h" // warn_unused_function
16 #include "plugin.hxx"
18 namespace {
20 class InlineVisible:
21 public RecursiveASTVisitor<InlineVisible>, public loplugin::Plugin
23 public:
24 explicit InlineVisible(loplugin::InstantiationData const & data):
25 Plugin(data) {}
27 void run() override
28 { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
30 bool VisitFunctionDecl(FunctionDecl const * decl);
33 bool InlineVisible::VisitFunctionDecl(FunctionDecl const * decl) {
34 if (!ignoreLocation(decl) && decl->isInlineSpecified()) {
35 VisibilityAttr * attr = decl->getAttr<VisibilityAttr>();
36 if (attr != nullptr && attr->getVisibility() == VisibilityAttr::Default)
38 report(
39 DiagnosticsEngine::Warning,
40 ("Function explicitly declared both inline and "
41 " visibility=default"),
42 decl->getLocation())
43 << decl->getSourceRange();
46 return true;
49 loplugin::Plugin::Registration<InlineVisible> X("inlinevisible");
53 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */