/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ #ifndef LO_CLANG_SHARED_PLUGINS
bool StringViewDangle::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* cxxOperatorCallExpr)
{ if (ignoreLocation(cxxOperatorCallExpr)) returntrue;
auto op = cxxOperatorCallExpr->getOperator(); if (op != OO_Equal) returntrue; if (!loplugin::TypeCheck(cxxOperatorCallExpr->getType())
.ClassOrStruct("basic_string_view")
.StdNamespace()) returntrue; auto expr = IgnoreImplicitAndConversionOperator(cxxOperatorCallExpr->getArg(1)); auto tc = loplugin::TypeCheck(expr->getType()); if (!tc.Class("OUString").Namespace("rtl").GlobalNamespace()
&& !tc.Class("OString").Namespace("rtl").GlobalNamespace()) returntrue; if (!isa<MaterializeTemporaryExpr>(expr)) returntrue;
report(DiagnosticsEngine::Warning, "view pointing into temporary i.e. dangling",
cxxOperatorCallExpr->getExprLoc())
<< cxxOperatorCallExpr->getSourceRange(); returntrue;
}
bool StringViewDangle::VisitVarDecl(VarDecl const* varDecl)
{ if (ignoreLocation(varDecl)) returntrue; if (!loplugin::TypeCheck(varDecl->getType()).ClassOrStruct("basic_string_view").StdNamespace()) returntrue; if (!varDecl->hasInit()) returntrue; auto expr = IgnoreImplicitAndConversionOperator(varDecl->getInit()); auto tc = loplugin::TypeCheck(expr->getType()); if (!tc.Class("OUString").Namespace("rtl").GlobalNamespace()
&& !tc.Class("OString").Namespace("rtl").GlobalNamespace()) returntrue; if (!isa<MaterializeTemporaryExpr>(expr)) returntrue;
report(DiagnosticsEngine::Warning, "view pointing into temporary i.e. dangling",
varDecl->getLocation())
<< varDecl->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 ist noch experimentell.