/* -*- 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. *
*/ #ifndef LO_CLANG_SHARED_PLUGINS
#include"check.hxx" #include"plugin.hxx"
/* This is a compile check.
Warns about functions with static keyword in an unnamed namespace.
*/
namespace loplugin
{
class RedundantStatic
: public loplugin::FilteringPlugin<RedundantStatic>
{ public: explicit RedundantStatic( const InstantiationData& data );
bool VisitVarDecl(VarDecl const * decl) { if (ignoreLocation(decl)) { returntrue;
} if (!decl->isFileVarDecl() || decl->isStaticDataMember()) { returntrue;
} if (decl->getStorageClass() != SC_Static) { returntrue;
} if (decl->isInAnonymousNamespace()) { auto loc = decl->getBeginLoc(); while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
} if (compiler.getSourceManager().isMacroBodyExpansion(loc)) { autoconst name = Lexer::getImmediateMacroName(
loc, compiler.getSourceManager(), compiler.getLangOpts()); if (name == "CPPUNIT_TEST_SUITE_REGISTRATION"
|| name == "CPPUNIT_TEST_SUITE_NAMED_REGISTRATION")
{ // Those macros contain a `static`, but are often used in an unnamed // namespace, so filter them out: returntrue;
}
}
report(
DiagnosticsEngine::Warning, "redundant 'static' keyword in unnamed namespace",
decl->getLocation())
<< decl->getSourceRange(); returntrue;
} if (decl->isInline()) { returntrue;
} if (!loplugin::TypeCheck(decl->getType()).ConstNonVolatile()) { returntrue;
}
report(
DiagnosticsEngine::Warning, "non-inline variable of non-volatile const-qualified type is redundantly marked as" " 'static'",
decl->getLocation())
<< decl->getSourceRange(); returntrue;
}
};
RedundantStatic::RedundantStatic( const InstantiationData& data )
: FilteringPlugin( data )
{
}
void RedundantStatic::run()
{ if (preRun()) {
TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.