Remove exec bits from docx
[LibreOffice.git] / compilerplugins / clang / externandnotdefined.cxx
blob8b04670b99bb3deba51b102f89d39df90859a493
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 #ifndef LO_CLANG_SHARED_PLUGINS
12 #include <string>
14 #include "compat.hxx"
15 #include "plugin.hxx"
17 // Having an extern prototype for a method in a module and not actually declaring that method is dodgy.
20 namespace {
22 class ExternAndNotDefined:
23 public loplugin::FilteringPlugin<ExternAndNotDefined>
25 public:
26 explicit ExternAndNotDefined(loplugin::InstantiationData const & data): FilteringPlugin(data) {}
28 virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
30 bool VisitFunctionDecl(const FunctionDecl * decl);
33 bool ExternAndNotDefined::VisitFunctionDecl(const FunctionDecl * functionDecl) {
34 if (ignoreLocation(functionDecl)) {
35 return true;
37 if (functionDecl->isDefined() || compat::isPureVirtual(functionDecl)
38 || (functionDecl->getLinkageAndVisibility().getLinkage()
39 != compat::Linkage::External)) {
40 return true;
42 //TODO, filtering out anything template for now:
43 if (functionDecl->isDependentContext()) {
44 return true;
46 CXXRecordDecl const * r = dyn_cast<CXXRecordDecl>(functionDecl->getDeclContext());
47 if (r != nullptr && r->getTemplateSpecializationKind() != TSK_Undeclared) {
48 return true;
50 // this is the bison/flex C API, it has to be defined this way
51 std::string functionName = functionDecl->getNameAsString();
52 if (functionName == "yyerror" || functionName == "yyparse" || functionName == "yylex") {
53 return true;
55 // see vcl/unx/gtk/app/gtksys.cxx, typename conflicts prevent using the right include
56 if (functionName == "gdk_x11_screen_get_screen_number") {
57 return true;
59 if (!compiler.getSourceManager().isInMainFile(functionDecl->getLocation()))
61 return true;
63 report(
64 DiagnosticsEngine::Warning,
65 "extern prototype in main file without definition",
66 functionDecl->getLocation())
67 << functionDecl->getSourceRange();
68 return true;
72 loplugin::Plugin::Registration< ExternAndNotDefined > externandnotdefined("externandnotdefined");
76 #endif // LO_CLANG_SHARED_PLUGINS
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */