summaryrefslogtreecommitdiff
path: root/share/qtcreator/cplusplus/examples/clazy_example.cpp
blob: 5b3c3711839a57cfbdf38baa29b96ce38d80fab8 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

// -Wclazy-qt-macros
#ifdef Q_OS_XXX
#endif

#include <QCoreApplication>
#include <QDateTime>
#include <QFileInfo>
#include <QMap>
#include <QObject>
#include <QPoint>
#include <QPointer>

// -Wclazy-ctor-missing-parent-argument
class TestObject : public QObject
{
    Q_OBJECT

public:
    TestObject();
    TestObject(const TestObject& other) {}

    bool event(QEvent *event) override
    {
        // -Wclazy-base-class-event
        return false;
    }

public slots:
    void someSlot() {}

    // -Wclazy-function-args-by-value
    void someOtherSlot(const QPoint &point)
    {
        point.isNull();
    }

signals:
    void someSignal();
private:
    char m_bigArray[100];
};

// -Wclazy-copyable-polymorphic
class TestObjectDerived : public TestObject
{

};

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

TestObject::TestObject()
{
    // -Wclazy-old-style-connect
    QObject::connect(this, SIGNAL(someSlot()), SLOT(someOtherSlot()));

    int a;

    // -Wclazy-connect-non-signal, -Wclazy-lambda-in-connect
    QObject::connect(this, &TestObject::someSlot, [&a]() {
        return;
    });

    // -Wclazy-incorrect-emit
    someSignal();

    QMap<int, int *> map;

    // -Wclazy-unused-non-trivial-variable, -Wclazy-mutable-container-key
    QMap<QPointer<QObject>, int> map2;

    // -Wclazy-container-anti-pattern, -Wclazy-range-loop
    for (auto value : map.values()) {
    }

    // -Wclazy-qdeleteall
    qDeleteAll(map.values());
    for (auto it = getList().begin(); it != getList().end(); ++it) { // -Wclazy-detaching-temporary, -Wclazy-temporary-iterator
    }

    // -Wclazy-inefficient-qlist-soft
    QList<TestObject> list;

    // -Wclazy-range-loop
    for (auto obj : list) {
    }

    // -Wclazy-qfileinfo-exists
    // -Wclazy-qstring-allocations
    QFileInfo("filename").exists();

    // -Wclazy-qlatin1string-non-ascii
    QLatin1String latinStr("ййй");

    QString str = latinStr;

    // -Wclazy-qstring-left
    str = str.left(1);

    bool ok;

    // -Wclazy-qstring-ref
    str.mid(5).toInt(&ok);

    // -Wclazy-qstring-arg
    (void) QString("%1 %2").arg("1").arg("2");
}