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 (58 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download | duplicates (5)
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
#include <QtCore/QList>
#include <QtCore/QVariant>
#include <vector>
#include <QtCore/QHash>
Q_GLOBAL_STATIC(QList<int>, s_list);

QList<int> getList()
{
  QList<int> list;
  list << 1;
  return list;
}

QList<int>& getListRef()
{
  static QList<int> list;
  return list;
}

void test()
{
    for (auto it = getList().begin(); it != getList().end(); ++it) {} // Warning
    for (auto it = getListRef().begin(); it != getListRef().end(); ++it) {} // OK

    QList<int> localList;
    for (auto it = localList.begin(); it != localList.end(); ++it) {} // OK
    localList.cbegin(); // OK
    getListRef().cbegin(); // OK
    getList().cbegin(); // Warning

    s_list->cbegin(); // OK
    QVariant variant;
    variant.toList().cbegin(); // OK
}

void acceptsInt(int) {}

void testDereference()
{
    int value = *getList().cbegin(); // OK
    value = *(getList().cbegin()); // OK
    acceptsInt(*getList().cbegin()); //OK
    const QHash<int, QList<int> > listOfLists;
    int ns = 1;
    for (auto it = listOfLists[ns].constBegin(); it != listOfLists[ns].constEnd(); ++it) {} // OK

}

QHash<int,int> getHash()
{
    return {};
}

void testMember()
{
    getHash().cbegin(); // Warning
    getHash().cbegin().value(); // OK
}