| 1 |
#include <QtCore/QString> |
| 2 |
#include <QtCore/QList> |
| 3 |
#include <QtCore/QVector> |
| 4 |
#include <QtCore/QByteArray> |
| 5 |
#include <QtCore/QRect> |
| 6 |
#include <QtCore/QMutex> |
| 7 |
#include <QtCore/QScopedPointer> |
| 8 |
#include <QtCore/QScopeGuard> |
| 9 |
#include "other.h" |
| 10 |
|
| 11 |
|
| 12 |
extern void external(QString); |
| 13 |
|
| 14 |
QString test() |
| 15 |
{ |
| 16 |
QString s; // Warning |
| 17 |
QString s1, s2; // Warning for s2 |
| 18 |
QString s3; // OK |
| 19 |
external(s1); |
| 20 |
|
| 21 |
return s3; |
| 22 |
return {}; |
| 23 |
} |
| 24 |
|
| 25 |
struct MyRAII |
| 26 |
{ |
| 27 |
MyRAII(); |
| 28 |
~MyRAII(); |
| 29 |
}; |
| 30 |
|
| 31 |
void testRAII() |
| 32 |
{ |
| 33 |
MyRAII m; // Warn, not blacklisted |
| 34 |
} |
| 35 |
|
| 36 |
void testFor() |
| 37 |
{ |
| 38 |
QStringList l; |
| 39 |
for (QString s : l) // OK |
| 40 |
s; |
| 41 |
|
| 42 |
foreach (QString s, l) // OK |
| 43 |
s; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
void test4() |
| 48 |
{ |
| 49 |
QList<int> l; //Warn |
| 50 |
QVector<int> v; //Warn |
| 51 |
QByteArray b; //Warn |
| 52 |
QRect r; // Warn |
| 53 |
FOO(QRect) r2; // OK |
| 54 |
r2.setX(0); |
| 55 |
} |
| 56 |
|
| 57 |
void mutex() |
| 58 |
{ |
| 59 |
auto myGuard = qScopeGuard([](){}); // OK, this needs to be around |
| 60 |
QMutex m; |
| 61 |
QMutexLocker ml(&m); // OK, is uninteresting |
| 62 |
QScopedPointer<QMutex> p(&m); // OK, is uninteresting |
| 63 |
} |
| 64 |
|
| 65 |
struct MyBlacklistedType |
| 66 |
{ |
| 67 |
MyBlacklistedType(); |
| 68 |
~MyBlacklistedType(); |
| 69 |
}; |
| 70 |
|
| 71 |
void testUserWhitelist() |
| 72 |
{ |
| 73 |
MyBlacklistedType m; // OK, blacklisted |
| 74 |
} |