2016-03-31 08:49:20 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* Based on LLVM/Clang.
|
|
|
|
*
|
|
|
|
*/
|
2019-07-16 08:13:59 +02:00
|
|
|
#ifndef LO_CLANG_SHARED_PLUGINS
|
|
|
|
|
2016-03-31 08:49:20 +02:00
|
|
|
#include "plugin.hxx"
|
2016-06-29 09:15:05 +02:00
|
|
|
|
2016-03-31 08:49:20 +02:00
|
|
|
/*
|
|
|
|
This is a compile check.
|
|
|
|
|
|
|
|
Warns about functions with static keyword in an unnamed namespace.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace loplugin
|
|
|
|
{
|
|
|
|
|
|
|
|
class StaticAnonymous
|
2018-08-23 14:35:15 +02:00
|
|
|
: public loplugin::FilteringPlugin<StaticAnonymous>
|
2016-03-31 08:49:20 +02:00
|
|
|
{
|
|
|
|
public:
|
2016-04-26 15:50:12 +02:00
|
|
|
explicit StaticAnonymous( const InstantiationData& data );
|
2016-03-31 08:49:20 +02:00
|
|
|
virtual void run() override;
|
2019-07-16 08:13:59 +02:00
|
|
|
bool VisitFunctionDecl( const FunctionDecl* func );
|
2016-03-31 08:49:20 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
StaticAnonymous::StaticAnonymous( const InstantiationData& data )
|
2018-08-23 14:35:15 +02:00
|
|
|
: FilteringPlugin( data )
|
2016-03-31 08:49:20 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void StaticAnonymous::run()
|
|
|
|
{
|
|
|
|
TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-16 08:13:59 +02:00
|
|
|
bool StaticAnonymous::VisitFunctionDecl( const FunctionDecl* func )
|
2016-03-31 08:49:20 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
if( ignoreLocation( func ) )
|
|
|
|
return true;
|
|
|
|
if( func -> isInAnonymousNamespace () )
|
|
|
|
{
|
2016-06-29 09:15:05 +02:00
|
|
|
if ( !isa<CXXMethodDecl>(func) && !func->isInExternCContext() )
|
2016-03-31 08:49:20 +02:00
|
|
|
{
|
|
|
|
if(func-> getStorageClass() == SC_Static)
|
|
|
|
{
|
|
|
|
report( DiagnosticsEngine::Warning,
|
|
|
|
"redundant 'static' keyword in unnamed namespace",
|
2018-08-10 12:35:21 +02:00
|
|
|
compat::getBeginLoc(func));
|
2016-03-31 08:49:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the plugin action with the LO plugin handling.
|
2019-07-16 08:13:59 +02:00
|
|
|
static Plugin::Registration< StaticAnonymous > staticanonymous("staticanonymous");
|
2016-03-31 08:49:20 +02:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-07-16 08:13:59 +02:00
|
|
|
#endif // LO_CLANG_SHARED_PLUGINS
|
|
|
|
|
2016-03-31 08:49:20 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|