aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/range-loop/main.cpp28
-rw-r--r--tests/range-loop/main.cpp.expected5
-rw-r--r--tests/range-loop/main.cpp_fixed.cpp.expected38
3 files changed, 66 insertions, 5 deletions
diff --git a/tests/range-loop/main.cpp b/tests/range-loop/main.cpp
index e3eadd14..39520039 100644
--- a/tests/range-loop/main.cpp
+++ b/tests/range-loop/main.cpp
@@ -209,3 +209,31 @@ void test_add_ref_fixits()
s.clear();
}
}
+
+struct SomeStruct
+{
+ QStringList m_list;
+ void test_add_qasconst_fixits()
+ {
+ for (const auto &s : m_list) {} // Warn
+ }
+
+ QStringList getList();
+};
+
+
+void test_add_qasconst_fixits()
+{
+ SomeStruct f;
+ for (const auto &s : f.m_list) {} // Warn
+
+ SomeStruct *f2;
+ for (const auto &s : f2->m_list) {} // Warn
+
+ QStringList locallist = f.getList();
+ for (const auto &s : locallist) {} // Warn
+
+ for (const auto &s : getQtList()) {} // Warn
+
+ for (const auto &s : f.getList()) {} // Warn
+}
diff --git a/tests/range-loop/main.cpp.expected b/tests/range-loop/main.cpp.expected
index 8985dfcb..94e1959b 100644
--- a/tests/range-loop/main.cpp.expected
+++ b/tests/range-loop/main.cpp.expected
@@ -7,3 +7,8 @@ range-loop/main.cpp:123:10: warning: Missing reference in range-for with non tri
range-loop/main.cpp:169:5: warning: c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop]
range-loop/main.cpp:201:10: warning: Missing reference in range-for with non trivial type (QString) [-Wclazy-range-loop]
range-loop/main.cpp:202:10: warning: Missing reference in range-for with non trivial type (QString) [-Wclazy-range-loop]
+range-loop/main.cpp:218:10: warning: c++11 range-loop might detach Qt container (QStringList) [-Wclazy-range-loop]
+range-loop/main.cpp:228:5: warning: c++11 range-loop might detach Qt container (QStringList) [-Wclazy-range-loop]
+range-loop/main.cpp:231:5: warning: c++11 range-loop might detach Qt container (QStringList) [-Wclazy-range-loop]
+range-loop/main.cpp:236:5: warning: c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop]
+range-loop/main.cpp:238:5: warning: c++11 range-loop might detach Qt container (QStringList) [-Wclazy-range-loop]
diff --git a/tests/range-loop/main.cpp_fixed.cpp.expected b/tests/range-loop/main.cpp_fixed.cpp.expected
index d18b397c..09e9a255 100644
--- a/tests/range-loop/main.cpp_fixed.cpp.expected
+++ b/tests/range-loop/main.cpp_fixed.cpp.expected
@@ -34,7 +34,7 @@ void testQtContainer()
{
QList<int> qt_container;
receivingList(qt_container);
- for (int i : qt_container) { // Warning
+ for (int i : qAsConst(qt_container)) { // Warning
}
const QList<int> const_qt_container;
@@ -44,8 +44,8 @@ void testQtContainer()
for (int i : getQtList()) { // Warning
}
- for (int i : qt_container) { } // Warning
- for (const int &i : qt_container) { } // Warning
+ for (int i : qAsConst(qt_container)) { } // Warning
+ for (const int &i : qAsConst(qt_container)) { } // Warning
for (int &i : qt_container) { } // OK
@@ -76,7 +76,7 @@ void testQMultiMapDetach()
{
QMultiMap<int,int> m;
receivingMap(m);
- for (int i : m) {
+ for (int i : qAsConst(m)) {
}
}
@@ -166,7 +166,7 @@ void testBug367485()
QList<int> list2;
receivingList(list2);
- for (auto a : list2) {} // Warning
+ for (auto a : qAsConst(list2)) {} // Warning
QList<int> list3;
for (auto a : list3) {} // OK
@@ -209,3 +209,31 @@ void test_add_ref_fixits()
s.clear();
}
}
+
+struct SomeStruct
+{
+ QStringList m_list;
+ void test_add_qasconst_fixits()
+ {
+ for (const auto &s : qAsConst(m_list)) {} // Warn
+ }
+
+ QStringList getList();
+};
+
+
+void test_add_qasconst_fixits()
+{
+ SomeStruct f;
+ for (const auto &s : qAsConst(f.m_list)) {} // Warn
+
+ SomeStruct *f2;
+ for (const auto &s : qAsConst(f2->m_list)) {} // Warn
+
+ QStringList locallist = f.getList();
+ for (const auto &s : locallist) {} // Warn
+
+ for (const auto &s : getQtList()) {} // Warn
+
+ for (const auto &s : f.getList()) {} // Warn
+}