File indexing completed on 2024-04-28 05:38:28

0001 /*
0002     SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB a KDAB Group company info@kdab.com
0003     SPDX-FileContributor: SĂ©rgio Martins <sergio.martins@kdab.com>
0004 
0005     SPDX-FileCopyrightText: 2015 Sergio Martins <smartins@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef DETACHING_TEMPORARIES_H
0011 #define DETACHING_TEMPORARIES_H
0012 
0013 #include "checks/detachingbase.h"
0014 
0015 #include <llvm/ADT/StringRef.h>
0016 
0017 #include <map>
0018 #include <string>
0019 #include <vector>
0020 
0021 class ClazyContext;
0022 namespace clang
0023 {
0024 class CXXMethodDecl;
0025 class Stmt;
0026 } // namespace clang
0027 
0028 /**
0029  * Finds places where you're calling non-const member functions on temporaries.
0030  *
0031  * For example getList().first(), which would detach if the container is shared.
0032  * See README-deatching-temporary for more information
0033  */
0034 class DetachingTemporary : public DetachingBase
0035 {
0036 public:
0037     DetachingTemporary(const std::string &name, ClazyContext *context);
0038     void VisitStmt(clang::Stmt *stm) override;
0039 
0040 private:
0041     bool isDetachingMethod(clang::CXXMethodDecl *method) const;
0042     std::map<llvm::StringRef, std::vector<llvm::StringRef>> m_writeMethodsByType;
0043 };
0044 
0045 #endif