*/ namespace
{ class StaticConstexpr final : public loplugin::FilteringPlugin<StaticConstexpr>
{ public: explicit StaticConstexpr(loplugin::InstantiationData const& data)
: FilteringPlugin(data)
{
}
bool VisitVarDecl(const VarDecl* varDecl)
{ if (ignoreLocation(varDecl)) returntrue; if (!varDecl->isConstexpr()) returntrue; if (!varDecl->isLocalVarDecl()) returntrue; if (varDecl->isStaticLocal()) returntrue; if (autoconst functionDecl = dyn_cast_or_null<FunctionDecl>(varDecl->getDeclContext()))
{ // cannot convert these, definition of a static variable in a constexpr function is a C++23 extension if (functionDecl->isConstexpr()) returntrue;
} if (varDecl->getType()->isBuiltinType() || varDecl->getType()->isEnumeralType()) returntrue; // ignore the o3tl::getConversionMulDiv stuff
loplugin::TypeCheck tc(varDecl->getType()); if (tc.ClassOrStruct("pair").StdNamespace()) returntrue; if (tc.Struct("m_and_d").Namespace("detail").Namespace("o3tl")) returntrue; if (tc.ClassOrStruct("TypedWhichId")) returntrue; if (tc.ClassOrStruct("Color")) returntrue;
report(DiagnosticsEngine::Warning, "function-local constexpr vars should be declared static", varDecl->getBeginLoc())
<< varDecl->getSourceRange(); returntrue;
}
bool preRun() override
{ if (!compiler.getLangOpts().CPlusPlus) returnfalse; returntrue;
}
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.