1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 // Find occurrences of std::move on const-qualified types. While there might theoretically be
11 // legitimate uses for such (for which this plugin would generate false positives and would need to
12 // be updated), in practice they tend to point at suspicious code that should be cleaned up in some
15 #ifndef LO_CLANG_SHARED_PLUGINS
22 class ConstMove final
: public loplugin::FilteringPlugin
<ConstMove
>
25 explicit ConstMove(loplugin::InstantiationData
const& data
)
26 : FilteringPlugin(data
)
30 bool preRun() override
{ return compiler
.getLangOpts().CPlusPlus
; }
36 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
40 bool VisitCallExpr(CallExpr
const* expr
)
42 if (ignoreLocation(expr
))
46 auto const t
= expr
->getType();
47 if (!t
.isConstQualified())
51 auto const d
= expr
->getDirectCallee();
56 if (!loplugin::DeclCheck(d
).Function("move").StdNamespace())
60 switch (expr
->getNumArgs())
67 if (!isa
<CXXDefaultArgExpr
>(expr
->getArg(1)))
73 report(DiagnosticsEngine::Warning
, "suspicious 'std::move' from %0 to const-qualified %1",
75 << expr
->getArg(0)->IgnoreImplicit()->getType() << t
<< expr
->getSourceRange();
80 static loplugin::Plugin::Registration
<ConstMove
> constmove("constmove");
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */