File: main.cpp

package info (click to toggle)
clazy 1.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,384 kB
  • sloc: cpp: 24,969; python: 1,429; xml: 448; sh: 237; makefile: 48
file content (99 lines) | stat: -rw-r--r-- 2,928 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <QtCore/QString>
#include <QtCore/QMap>
#include <QtCore/QHash>
#include <QtCore/QVector>
#include <QtCore/QList>
#include <QtCore/QSet>
#include <QtCore/QVarLengthArray>
#include <vector>
void testTypedefedIterators()
{
    QVector<int> vec;
    QString str;
    QVarLengthArray<int, 5> vla;

    QVector<int>::const_iterator it1 = vec.begin(); // Warning
    QString::const_iterator it7 = str.begin(); // Warning
    QString::const_iterator it8 = str.cbegin(); // OK
    QVarLengthArray<int, 5>::const_iterator it9 = vla.begin(); // Ok, not shared
    QVarLengthArray<int, 5>::const_iterator it10 = vla.cbegin(); // OK

    // These are not implemented yet. Can't figure it out.. the QualType doesn't have the typedef information, only T*..

    if (vec.cend() == vec.end()) {} // OK
    if (vec.end() == vec.cend()) {} // Warning
    if (vec.cend() == vec.cend()) {} // OK
    if (vec.end() == vec.end()) {} // OK
    str.begin() == str.cbegin(); // Warning
    vla.begin() == vla.cbegin(); // OK, not shared
}

void test()
{
    QMap<int,int> map;
    QHash<int,int> hash;
    QList<int> list;
    QSet<int> set;


    QList<int>::const_iterator it2 = list.begin(); // Warning
    QHash<int,int>::const_iterator it3 = hash.begin(); // Warning
    QHash<int,int>::const_iterator it4 = hash.cbegin(); // OK
    QMap<int,int>::const_iterator it5 = map.begin(); // Warning
    QMap<int,int>::const_iterator it6 = map.cbegin(); // OK
    QSet<int>::const_iterator it11 = set.begin(); // Warning
    it11 = set.cbegin(); // OK

    hash.begin() == hash.cbegin(); // Warning
    list.begin() == list.cbegin(); // Warning
    set.begin() == set.cbegin(); // Warning
    map.begin() == map.cbegin(); // Warning

    hash.begin() == hash.begin(); // OK
    list.begin() == list.begin(); // OK
    set.begin() == set.begin(); // OK
    map.begin() == map.begin(); // OK

    hash.cbegin() == hash.cbegin(); // OK
    list.cbegin() == list.cbegin(); // OK
    set.cbegin() == set.cbegin(); // OK
    map.cbegin() == map.cbegin(); // OK

    QHash<int,int>::const_iterator it12 = QHash<int,int>::const_iterator(hash.begin()); // OK
}

void test2()
{
    QVector<int> v;
    v.erase(std::remove_if(v.begin(), v.end(), [](int){ return false; }),
            v.end()); // OK

    QVarLengthArray<int, 5> vla;
    vla.erase(std::remove_if(vla.begin(), vla.end(), [](int){ return false; }),
              vla.end()); // OK, not implicit shared
}


void testStdVector()
{
    std::vector<int> v;
    std::vector<int>::const_iterator it = v.begin(); // OK
}


struct Bar {
    bool foo() const
    {
        return mFooIt != mFoo.end(); // OK, since mFooIt is a member, it won't make anything detach
    }
    QVector<int> mFoo;
    QVector<int>::iterator mFooIt;
};

#include <QtCore/QJsonObject>
void testJsonObj()
{
    QJsonObject obj;
    if (obj.begin() == obj.end()) {} // OK
    if (obj.begin() == obj.constEnd()) {} // Warn
}