Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / compilerplugins / clang / staticanonymous.cxx
blob92d18c4017d8d0f36edb1cc7580bfca6e7b4911d
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 * Based on LLVM/Clang.
7 */
8 #include "plugin.hxx"
11 This is a compile check.
13 Warns about functions with static keyword in an unnamed namespace.
16 namespace loplugin
19 class StaticAnonymous
20 : public RecursiveASTVisitor< StaticAnonymous >
21 , public Plugin
23 public:
24 explicit StaticAnonymous( const InstantiationData& data );
25 virtual void run() override;
26 bool VisitFunctionDecl( FunctionDecl* func );
30 StaticAnonymous::StaticAnonymous( const InstantiationData& data )
31 : Plugin( data )
35 void StaticAnonymous::run()
37 TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
41 bool StaticAnonymous::VisitFunctionDecl( FunctionDecl* func )
44 if( ignoreLocation( func ) )
45 return true;
46 if( func -> isInAnonymousNamespace () )
48 if ( !isa<CXXMethodDecl>(func) && !func->isInExternCContext() )
50 if(func-> getStorageClass() == SC_Static)
52 report( DiagnosticsEngine::Warning,
53 "redundant 'static' keyword in unnamed namespace",
54 func->getLocStart());
59 return true;
62 // Register the plugin action with the LO plugin handling.
63 static Plugin::Registration< StaticAnonymous > X( "staticanonymous",true);
65 } // namespace
67 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */