Warning, /sdk/clazy/tests/range-loop-detach/main.cpp.fixed.expected is written in an unsupported language. File is not indexed.

0001 #include <QtCore/QList>
0002 #include <vector>
0003 #include <QtCore/QMap>
0004 #include <QtCore/QString>
0005 
0006 void receivingList(QList<int>);
0007 void receivingMap(QMultiMap<int,int>);
0008 
0009 using namespace std;
0010 
0011 QList<int> getQtList()
0012 {
0013     return {}; // dummy, not important
0014 }
0015 
0016 const QList<int> getConstQtList()
0017 {
0018     return {}; // dummy, not important
0019 }
0020 
0021 const QList<int> & getConstRefQtList()
0022 {
0023     static QList<int> foo;
0024     return foo;
0025 }
0026 
0027 void testQtContainer()
0028 {
0029     QList<int> qt_container;
0030     receivingList(qt_container);
0031     for (int i : qAsConst(qt_container)) { // Warning
0032     }
0033 
0034     const QList<int> const_qt_container;
0035     for (int i : const_qt_container) { // OK
0036     }
0037 
0038     for (int i : getQtList()) { // Warning
0039     }
0040 
0041     for (int i : qAsConst(qt_container)) { }  // Warning
0042     for (const int &i : qAsConst(qt_container)) { } // Warning
0043     for (int &i : qt_container) { } // OK
0044 
0045 
0046 
0047 
0048     for (int i : getConstQtList()) { // OK
0049     }
0050 
0051     for (int i : getConstRefQtList()) { // OK
0052     }
0053 
0054     vector<int> stl_container;
0055     for (int i : stl_container) { // OK
0056     }
0057 }
0058 
0059 class A {
0060 public:
0061     void foo()
0062     {
0063         for (int a : m_stlVec) {} // OK
0064     }
0065 
0066     std::vector<int> m_stlVec;
0067 };
0068 
0069 void testQMultiMapDetach()
0070 {
0071     QMultiMap<int,int> m;
0072     receivingMap(m);
0073     for (int i : qAsConst(m)) {
0074     }
0075 }
0076 
0077 void testBug367485()
0078 {
0079     QList<int> list;
0080     for (auto a : list) {} // OK
0081 
0082     QList<int> list2;
0083     receivingList(list2);
0084     for (auto a : qAsConst(list2)) {} // Warning
0085 
0086     QList<int> list3;
0087     for (auto a : list3) {} // OK
0088     receivingList(list3);
0089 
0090     QList<int> list4;
0091     foreach (auto a, list4) {} // OK
0092     receivingList(list4);
0093 }
0094 
0095 struct SomeStruct
0096 {
0097     QStringList m_list;
0098     void test_add_qasconst_fixits()
0099     {
0100          for (const auto &s : qAsConst(m_list)) {} // Warn
0101     }
0102 
0103     QStringList getList();
0104 };
0105 
0106 
0107 void test_add_qasconst_fixits()
0108 {
0109     SomeStruct f;
0110     for (const auto &s : qAsConst(f.m_list)) {}  // Warn
0111 
0112     SomeStruct *f2;
0113     for (const auto &s : qAsConst(f2->m_list)) {}  // Warn
0114 
0115     QStringList locallist = f.getList();
0116     for (const auto &s : qAsConst(locallist)) {} // Warn
0117 
0118     for (const auto &s : getQtList()) {} // Warn
0119 
0120     for (const auto &s : f.getList()) {} // Warn
0121 }