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/.
9 #ifndef LO_CLANG_SHARED_PLUGINS
22 Check for calls to operator== on a std::container< std::unique_ptr >, which is not useful,
23 because std::container will compare the pointers so it is never true
29 public loplugin::FilteringPlugin
<PtrVector
>
32 explicit PtrVector(loplugin::InstantiationData
const & data
): FilteringPlugin(data
)
35 virtual void run() override
38 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
41 bool shouldVisitTemplateInstantiations () const { return true; }
43 bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr
* );
46 bool PtrVector::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr
* expr
)
48 if (ignoreLocation(expr
)) {
51 if (expr
->getOperator() != clang::OverloadedOperatorKind::OO_EqualEqual
52 && expr
->getOperator() != clang::OverloadedOperatorKind::OO_ExclaimEqual
)
56 if (isa
<CXXNullPtrLiteralExpr
>(expr
->getArg(1))) {
59 const Expr
* argExpr
= expr
->getArg(0);
60 std::string s
= argExpr
->getType().getDesugaredType(compiler
.getASTContext()).getAsString();
61 if (s
.find("iterator") != std::string::npos
62 || (loplugin::TypeCheck(argExpr
->getType()).Class("__wrap_iter").Namespace("__1")
67 if (s
.find("array") == std::string::npos
&& s
.find("deque") == std::string::npos
68 && s
.find("list") == std::string::npos
&& s
.find("vector") == std::string::npos
69 && s
.find("set") == std::string::npos
&& s
.find("map") == std::string::npos
70 && s
.find("stack") == std::string::npos
&& s
.find("queue") == std::string::npos
)
74 if (s
.find("unique_ptr") != std::string::npos
) {
75 expr
->getArg(1)->dump();
77 DiagnosticsEngine::Warning
,
78 "do not call operator== on a std container containing a unique_ptr " + s
,
85 loplugin::Plugin::Registration
< PtrVector
> ptrvector("ptrvector");
89 #endif // LO_CLANG_SHARED_PLUGINS
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */