Debian Codegraph @

src/checks/level1/foreach.h

raw
1 /*
2 SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB a KDAB Group company [email protected]
3 SPDX-FileContributor: Sérgio Martins <[email protected]>
4
5 SPDX-FileCopyrightText: 2015 Sergio Martins <[email protected]>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9
10 #ifndef FOREACH_DETACHMENTS_H
11 #define FOREACH_DETACHMENTS_H
12
13 #include "checkbase.h"
14
15 namespace clang
16 {
17 class ForStmt;
18 class ValueDecl;
19 }
20
21 /**
22 * - Foreach:
23 * - Finds places where you're detaching the foreach container.
24 * - Finds places where big or non-trivial types are passed by value instead of const-ref.
25 * - Finds places where you're using foreach on STL containers. It causes deep-copy.
26 * - For Range Loops:
27 * - Finds places where you're using C++11 for range loops with Qt containers. (potential detach)
28 */
29 class Foreach : public CheckBase
30 {
31 public:
32 using CheckBase::CheckBase;
33 void VisitStmt(clang::Stmt *stmt) override;
34
35 private:
36 void checkBigTypeMissingRef();
37 bool containsDetachments(clang::Stmt *stmt, clang::ValueDecl *containerValueDecl);
38 clang::ForStmt *m_lastForStmt = nullptr;
39 };
40
41 #endif