aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2019-05-09 15:38:49 +0100
committerSergio Martins <smartins@kde.org>2019-05-09 15:38:49 +0100
commit948a23ae1b1553cf67dc8b523236cc0e7dc74994 (patch)
treee32ae3a7ae942b1198fd3764f58ea6661dfba4db
parent008cdc9d14522a56d5410a7b37e4a0a2cb3c673a (diff)
inefficient-qlist: Dont warn for QVariantList
It's commonly used to interact with Qt API. This will be solved in Qt 6 anyway.
-rw-r--r--src/checks/inefficientqlistbase.cpp4
-rw-r--r--tests/inefficient-qlist/main.cpp8
-rw-r--r--tests/inefficient-qlist/main.cpp.expected1
3 files changed, 10 insertions, 3 deletions
diff --git a/src/checks/inefficientqlistbase.cpp b/src/checks/inefficientqlistbase.cpp
index 51fb104a..d75a2426 100644
--- a/src/checks/inefficientqlistbase.cpp
+++ b/src/checks/inefficientqlistbase.cpp
@@ -87,7 +87,7 @@ bool InefficientQListBase::shouldIgnoreVariable(VarDecl *varDecl) const
void InefficientQListBase::VisitDecl(clang::Decl *decl)
{
- VarDecl *varDecl = dyn_cast<VarDecl>(decl);
+ auto varDecl = dyn_cast<VarDecl>(decl);
if (!varDecl)
return;
@@ -97,7 +97,7 @@ void InefficientQListBase::VisitDecl(clang::Decl *decl)
return;
CXXRecordDecl *recordDecl = t->getAsCXXRecordDecl();
- if (!recordDecl || clazy::name(recordDecl) != "QList")
+ if (!recordDecl || clazy::name(recordDecl) != "QList" || type.getAsString() == "QVariantList")
return;
const std::vector<clang::QualType> types = clazy::getTemplateArgumentsTypes(recordDecl);
diff --git a/tests/inefficient-qlist/main.cpp b/tests/inefficient-qlist/main.cpp
index a451f0e3..ab6ba550 100644
--- a/tests/inefficient-qlist/main.cpp
+++ b/tests/inefficient-qlist/main.cpp
@@ -1,5 +1,5 @@
#include <QtCore/QList>
-
+#include <QtCore/QVariant>
@@ -47,3 +47,9 @@ void test_bug358740()
QList<int> list; // OK
int a, b;
}
+
+void testQVariantList()
+{
+ QList<QVariant> list1; // Warn
+ QVariantList list2; // OK, to interact with Qt api probably
+}
diff --git a/tests/inefficient-qlist/main.cpp.expected b/tests/inefficient-qlist/main.cpp.expected
index d6daa1d1..8d9ad803 100644
--- a/tests/inefficient-qlist/main.cpp.expected
+++ b/tests/inefficient-qlist/main.cpp.expected
@@ -1,3 +1,4 @@
inefficient-qlist/main.cpp:24:5: warning: Use QVector instead of QList for type with size 9 bytes [-Wclazy-inefficient-qlist]
inefficient-qlist/main.cpp:38:11: warning: Use QVector instead of QList for type with size 9 bytes [-Wclazy-inefficient-qlist]
inefficient-qlist/main.cpp:40:5: warning: Use QVector instead of QList for type with size 9 bytes [-Wclazy-inefficient-qlist]
+inefficient-qlist/main.cpp:53:5: warning: Use QVector instead of QList for type with size 16 bytes [-Wclazy-inefficient-qlist]