// Warn when a variable is referenced from its own initializer. This is not invalid in general (see // C++17 [basic.life]), but is at least suspicious.
namespace
{ class SelfInit : public loplugin::FilteringPlugin<SelfInit>
{ public: explicit SelfInit(loplugin::InstantiationData const& data)
: FilteringPlugin(data)
{
}
bool VisitDeclRefExpr(DeclRefExpr const* expr)
{ if (ignoreLocation(expr))
{ returntrue;
} for (autoconst& i : decls_)
{ if (expr->getDecl()->getCanonicalDecl() == i.canonical)
{
report(
DiagnosticsEngine::Warning,
("referencing a variable during its own initialization is error-prone and thus" " suspicious"),
expr->getLocation())
<< expr->getSourceRange();
report(DiagnosticsEngine::Note, "variable declared here", i.current->getLocation())
<< i.current->getSourceRange();
}
} 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.