aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2019-09-22 20:29:03 +0100
committerSergio Martins <smartins@kde.org>2019-09-22 20:29:03 +0100
commit590d2e0c42046c62f8a6230b79e3200437be5e03 (patch)
treece162c1d1eb0014d57efac43ff26052af2e3e850 /src
parent842ea022194297091080b9017f1cfa12ed473fa3 (diff)
Move containerNeverDetaches() into range-loop.cpp
It's a bit of an hack and very specific to range-loop, not something to be reused
Diffstat (limited to 'src')
-rw-r--r--src/QtUtils.cpp33
-rw-r--r--src/QtUtils.h12
-rw-r--r--src/checks/level1/range-loop.cpp45
3 files changed, 45 insertions, 45 deletions
diff --git a/src/QtUtils.cpp b/src/QtUtils.cpp
index 0d66bb1b..5fa0b7c6 100644
--- a/src/QtUtils.cpp
+++ b/src/QtUtils.cpp
@@ -205,39 +205,6 @@ bool clazy::isQtContainer(const CXXRecordDecl *record)
});
}
-bool clazy::containerNeverDetaches(const clang::VarDecl *valDecl, StmtBodyRange bodyRange) // clazy:exclude=function-args-by-value
-{
- // This helps for bug 367485
-
- if (!valDecl)
- return false;
-
- const auto context = dyn_cast<FunctionDecl>(valDecl->getDeclContext());
- if (!context)
- return false;
-
- bodyRange.body = context->getBody();
- if (!bodyRange.body)
- return false;
-
- if (valDecl->hasInit()) {
- if (auto cleanupExpr = dyn_cast<clang::ExprWithCleanups>(valDecl->getInit())) {
- if (auto ce = dyn_cast<clang::CXXConstructExpr>(cleanupExpr->getSubExpr())) {
- if (!ce->isListInitialization() && !ce->isStdInitListInitialization()) {
- // When initing via copy or move ctor there's possible detachments.
- return false;
- }
- }
- }
- }
-
- // TODO1: Being passed to a function as const should be OK
- if (Utils::isPassedToFunction(bodyRange, valDecl, false))
- return false;
-
- return true;
-}
-
bool clazy::isAReserveClass(CXXRecordDecl *recordDecl)
{
if (!recordDecl)
diff --git a/src/QtUtils.h b/src/QtUtils.h
index 88070672..ca9f6386 100644
--- a/src/QtUtils.h
+++ b/src/QtUtils.h
@@ -198,18 +198,6 @@ inline bool isTooBigForQList(clang::QualType qt, const clang::ASTContext *contex
bool recordHasCtorWithParam(clang::CXXRecordDecl *record, const std::string &paramType, bool &ok, int &numCtors);
/**
- * Returns true if we can prove the container doesn't detach.
- * Returns false otherwise, meaning that you can't conclude anything if false is returned.
- *
- * For true to be returned, all these conditions must verify:
- * - Container is a local variable
- * - It's not passed to any function
- * - It's not assigned to another variable
- */
-bool containerNeverDetaches(const clang::VarDecl *varDecl,
- StmtBodyRange bodyRange);
-
-/**
* Returns true if recordDecl is one of the container classes that supports reserve(), such
* as QList, QVector, etc.
*/
diff --git a/src/checks/level1/range-loop.cpp b/src/checks/level1/range-loop.cpp
index 8401cf13..e62d45aa 100644
--- a/src/checks/level1/range-loop.cpp
+++ b/src/checks/level1/range-loop.cpp
@@ -53,6 +53,51 @@ enum Fixit {
Fixit_AddqAsConst = 2
};
+namespace clazy {
+/**
+ * Returns true if we can prove the container doesn't detach.
+ * Returns false otherwise, meaning that you can't conclude anything if false is returned.
+ *
+ * For true to be returned, all these conditions must verify:
+ * - Container is a local variable
+ * - It's not passed to any function
+ * - It's not assigned to another variable
+ */
+bool containerNeverDetaches(const clang::VarDecl *valDecl, StmtBodyRange bodyRange) // clazy:exclude=function-args-by-value
+{
+ // This helps for bug 367485
+
+ if (!valDecl)
+ return false;
+
+ const auto context = dyn_cast<FunctionDecl>(valDecl->getDeclContext());
+ if (!context)
+ return false;
+
+ bodyRange.body = context->getBody();
+ if (!bodyRange.body)
+ return false;
+
+ if (valDecl->hasInit()) {
+ if (auto cleanupExpr = dyn_cast<clang::ExprWithCleanups>(valDecl->getInit())) {
+ if (auto ce = dyn_cast<clang::CXXConstructExpr>(cleanupExpr->getSubExpr())) {
+ if (!ce->isListInitialization() && !ce->isStdInitListInitialization()) {
+ // When initing via copy or move ctor there's possible detachments.
+ return false;
+ }
+ }
+ }
+ }
+
+ // TODO1: Being passed to a function as const should be OK
+ if (Utils::isPassedToFunction(bodyRange, valDecl, false))
+ return false;
+
+ return true;
+}
+}
+
+
RangeLoop::RangeLoop(const std::string &name, ClazyContext *context)
: CheckBase(name, context, Option_CanIgnoreIncludes)
{