1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
19 Check for calls to operator== on a std::container< std::unique_ptr >, which is not useful,
20 because std::container will compare the pointers so it is never true
26 public RecursiveASTVisitor
<PtrVector
>, public loplugin::Plugin
29 explicit PtrVector(loplugin::InstantiationData
const & data
): Plugin(data
)
32 virtual void run() override
34 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
37 bool shouldVisitTemplateInstantiations () const { return true; }
39 bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr
* );
42 bool PtrVector::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr
* expr
)
44 if (ignoreLocation(expr
)) {
47 if (expr
->getOperator() != clang::OverloadedOperatorKind::OO_EqualEqual
48 && expr
->getOperator() != clang::OverloadedOperatorKind::OO_ExclaimEqual
)
52 if (isa
<CXXNullPtrLiteralExpr
>(expr
->getArg(1))) {
55 const Expr
* argExpr
= expr
->getArg(0);
56 std::string s
= argExpr
->getType().getDesugaredType(compiler
.getASTContext()).getAsString();
57 if (s
.find("iterator") != std::string::npos
) {
60 if (s
.find("array") == std::string::npos
&& s
.find("deque") == std::string::npos
61 && s
.find("list") == std::string::npos
&& s
.find("vector") == std::string::npos
62 && s
.find("set") == std::string::npos
&& s
.find("map") == std::string::npos
63 && s
.find("stack") == std::string::npos
&& s
.find("queue") == std::string::npos
)
67 if (s
.find("unique_ptr") != std::string::npos
) {
68 expr
->getArg(1)->dump();
70 DiagnosticsEngine::Warning
,
71 "do not call operator== on a std container containing a unique_ptr " + s
,
78 loplugin::Plugin::Registration
< PtrVector
> X("ptrvector");
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */