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.