2017-04-18 18:04:27 +02:00
|
|
|
|
|
|
|
// Test library configuration for qt.cfg
|
|
|
|
//
|
|
|
|
// Usage:
|
2023-03-09 20:04:20 +01:00
|
|
|
// $ cppcheck --check-library --library=qt --enable=style,information --inconclusive --error-exitcode=1 --disable=missingInclude --inline-suppr test/cfg/qt.cpp
|
2017-04-18 18:04:27 +02:00
|
|
|
// =>
|
|
|
|
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
|
|
|
|
//
|
|
|
|
|
2019-01-07 14:40:21 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
2019-07-31 13:58:55 +02:00
|
|
|
#include <QVector>
|
2019-08-20 20:37:52 +02:00
|
|
|
#include <QStack>
|
2019-08-20 07:09:43 +02:00
|
|
|
#include <QByteArray>
|
|
|
|
#include <QList>
|
|
|
|
#include <QLinkedList>
|
2019-01-07 14:40:21 +01:00
|
|
|
#include <QtPlugin>
|
2019-02-06 13:23:05 +01:00
|
|
|
#include <QFile>
|
2019-02-12 10:21:56 +01:00
|
|
|
#include <cstdio>
|
2019-02-26 13:39:37 +01:00
|
|
|
#include <QCoreApplication>
|
2019-09-16 15:58:35 +02:00
|
|
|
#include <QLoggingCategory>
|
2023-01-07 23:29:47 +01:00
|
|
|
#include <QTest>
|
2019-01-07 14:40:21 +01:00
|
|
|
|
2017-04-18 18:04:27 +02:00
|
|
|
|
2017-04-20 17:43:28 +02:00
|
|
|
void QString1(QString s)
|
|
|
|
{
|
|
|
|
for (int i = 0; i <= s.size(); ++i) {
|
|
|
|
// cppcheck-suppress stlOutOfBounds
|
|
|
|
s[i] = 'x';
|
|
|
|
}
|
2017-04-18 18:04:27 +02:00
|
|
|
}
|
2017-04-18 18:47:35 +02:00
|
|
|
|
2022-08-30 18:08:24 +02:00
|
|
|
bool QString2()
|
2017-04-20 17:43:28 +02:00
|
|
|
{
|
|
|
|
QString s;
|
2022-08-29 12:25:10 +02:00
|
|
|
// cppcheck-suppress knownConditionTrueFalse
|
2017-04-20 17:43:28 +02:00
|
|
|
return s.size();
|
2017-04-18 19:26:54 +02:00
|
|
|
}
|
2019-01-07 14:40:21 +01:00
|
|
|
|
2019-08-15 10:23:05 +02:00
|
|
|
QString::iterator QString3()
|
|
|
|
{
|
|
|
|
QString qstring1;
|
|
|
|
QString qstring2;
|
2019-12-25 09:32:50 +01:00
|
|
|
// cppcheck-suppress mismatchingContainers
|
2019-08-15 10:23:05 +02:00
|
|
|
for (QString::iterator it = qstring1.begin(); it != qstring2.end(); ++it)
|
|
|
|
{}
|
|
|
|
|
|
|
|
QString::iterator it = qstring1.begin();
|
|
|
|
// cppcheck-suppress returnDanglingLifetime
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2022-01-10 07:36:49 +01:00
|
|
|
void QString4()
|
|
|
|
{
|
|
|
|
// cppcheck-suppress unusedVariable
|
|
|
|
QString qs;
|
|
|
|
}
|
|
|
|
|
2022-01-18 20:17:05 +01:00
|
|
|
// cppcheck-suppress passedByValue
|
|
|
|
bool QString5(QString s) { // #10710
|
|
|
|
return s.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress passedByValue
|
|
|
|
QStringList QString6(QString s) {
|
|
|
|
return QStringList{ "*" + s + "*" };
|
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress passedByValue
|
|
|
|
bool QString7(QString s, const QString& l) {
|
|
|
|
return l.startsWith(s);
|
|
|
|
}
|
|
|
|
|
2019-08-15 16:14:17 +02:00
|
|
|
void QByteArray1(QByteArray byteArrayArg)
|
|
|
|
{
|
|
|
|
for (int i = 0; i <= byteArrayArg.size(); ++i) {
|
|
|
|
// cppcheck-suppress stlOutOfBounds
|
|
|
|
byteArrayArg[i] = 'x';
|
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
byteArrayArg[byteArrayArg.length()] = 'a';
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
byteArrayArg[byteArrayArg.count()] = 'b';
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
printf("val: %c\n", byteArrayArg[byteArrayArg.size()]);
|
|
|
|
|
|
|
|
QByteArray byteArray1{'a', 'b'};
|
|
|
|
(void)byteArray1[1];
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
byteArray1.at(1);
|
|
|
|
}
|
|
|
|
|
2019-08-15 10:23:05 +02:00
|
|
|
void QList1(QList<int> intListArg)
|
|
|
|
{
|
|
|
|
for (int i = 0; i <= intListArg.size(); ++i) {
|
|
|
|
// cppcheck-suppress stlOutOfBounds
|
|
|
|
intListArg[i] = 1;
|
|
|
|
}
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
intListArg[intListArg.length()] = 5;
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
intListArg[intListArg.count()] = 10;
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
printf("val: %d\n", intListArg[intListArg.size()]);
|
|
|
|
|
|
|
|
QList<QString> qstringList1{"one", "two"};
|
|
|
|
(void)qstringList1[1];
|
|
|
|
|
|
|
|
QList<QString> qstringList2 = {"one", "two"};
|
|
|
|
(void)qstringList2[1];
|
|
|
|
qstringList2.clear();
|
2020-08-10 05:52:03 +02:00
|
|
|
// cppcheck-suppress containerOutOfBounds
|
2019-08-15 10:23:05 +02:00
|
|
|
(void)qstringList2[1];
|
|
|
|
|
|
|
|
QList<QString> qstringList3;
|
|
|
|
qstringList3 << "one" << "two";
|
|
|
|
(void)qstringList3[1];
|
2020-08-08 07:10:03 +02:00
|
|
|
// FIXME: The following should have a containerOutOfBounds suppression #9242
|
|
|
|
(void)qstringList3[3];
|
2019-08-15 10:23:05 +02:00
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringList3.startsWith("one");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringList3.endsWith("one");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringList3.count();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringList3.length();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringList3.size();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringList3.at(5);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)qstringList3.at(-5);
|
|
|
|
|
|
|
|
QList<QString> qstringList4;
|
|
|
|
// cppcheck-suppress containerOutOfBounds
|
|
|
|
(void)qstringList4[0];
|
|
|
|
qstringList4.append("a");
|
|
|
|
(void)qstringList4[0];
|
|
|
|
qstringList4.clear();
|
2020-08-10 05:52:03 +02:00
|
|
|
// cppcheck-suppress containerOutOfBounds
|
2019-08-15 10:23:05 +02:00
|
|
|
(void)qstringList4[0];
|
|
|
|
}
|
|
|
|
|
2022-01-12 22:03:57 +01:00
|
|
|
QList<int> QList2() { // #10556
|
|
|
|
QList<int> v;
|
2022-01-25 13:08:05 +01:00
|
|
|
|
2022-01-12 22:03:57 +01:00
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
v.append(i);
|
|
|
|
(void)v.at(i);
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2019-08-15 10:23:05 +02:00
|
|
|
QList<int>::iterator QList3()
|
|
|
|
{
|
|
|
|
QList<int> qlist1;
|
|
|
|
QList<int> qlist2;
|
2019-12-25 09:32:50 +01:00
|
|
|
// cppcheck-suppress mismatchingContainers
|
2019-08-15 10:23:05 +02:00
|
|
|
for (QList<int>::iterator it = qlist1.begin(); it != qlist2.end(); ++it)
|
|
|
|
{}
|
|
|
|
|
|
|
|
QList<int>::iterator it = qlist1.begin();
|
2019-12-25 09:32:50 +01:00
|
|
|
// cppcheck-suppress returnDanglingLifetime
|
2019-08-15 10:23:05 +02:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2019-08-20 07:09:43 +02:00
|
|
|
void QLinkedList1()
|
|
|
|
{
|
2022-01-10 07:36:49 +01:00
|
|
|
// cppcheck-suppress unreadVariable
|
2019-08-20 07:09:43 +02:00
|
|
|
QLinkedList<QString> qstringLinkedList1{"one", "two"};
|
|
|
|
|
|
|
|
QLinkedList<QString> qstringLinkedList2 = {"one", "two"};
|
|
|
|
qstringLinkedList2.clear();
|
|
|
|
|
|
|
|
QLinkedList<QString> qstringLinkedList3;
|
|
|
|
qstringLinkedList3 << "one" << "two";
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringLinkedList3.startsWith("one");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringLinkedList3.endsWith("one");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringLinkedList3.count();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringLinkedList3.size();
|
|
|
|
|
|
|
|
QLinkedList<QString> qstringLinkedList4;
|
|
|
|
qstringLinkedList4.append("a");
|
|
|
|
qstringLinkedList4.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
QLinkedList<int>::iterator QLinkedList3()
|
|
|
|
{
|
|
|
|
QLinkedList<int> intQLinkedList1;
|
|
|
|
QLinkedList<int> intQLinkedList2;
|
2019-12-25 09:32:50 +01:00
|
|
|
// cppcheck-suppress mismatchingContainers
|
2019-08-20 07:09:43 +02:00
|
|
|
for (QLinkedList<int>::iterator it = intQLinkedList1.begin(); it != intQLinkedList2.end(); ++it)
|
|
|
|
{}
|
|
|
|
|
|
|
|
QLinkedList<int>::iterator it = intQLinkedList1.begin();
|
2019-12-25 09:32:50 +01:00
|
|
|
// cppcheck-suppress returnDanglingLifetime
|
2019-08-20 07:09:43 +02:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2019-08-15 10:23:05 +02:00
|
|
|
void QStringList1(QStringList stringlistArg)
|
|
|
|
{
|
|
|
|
for (int i = 0; i <= stringlistArg.size(); ++i) {
|
|
|
|
// cppcheck-suppress stlOutOfBounds
|
|
|
|
stringlistArg[i] = "abc";
|
|
|
|
}
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
stringlistArg[stringlistArg.length()] = "ab";
|
|
|
|
stringlistArg[stringlistArg.length() - 1] = "ab"; // could be valid
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
stringlistArg[stringlistArg.count()] = "12";
|
|
|
|
stringlistArg[stringlistArg.count() - 1] = "12"; // could be valid
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
(void)stringlistArg[stringlistArg.size()];
|
|
|
|
(void)stringlistArg[stringlistArg.size() - 1]; // could be valid
|
|
|
|
|
|
|
|
QStringList qstringlist1{"one", "two"};
|
|
|
|
(void)qstringlist1[1];
|
|
|
|
|
|
|
|
QStringList qstringlist2 = {"one", "two"};
|
|
|
|
(void)qstringlist2[1];
|
|
|
|
|
|
|
|
QStringList qstringlist3;
|
|
|
|
qstringlist3 << "one" << "two";
|
|
|
|
(void)qstringlist3[1];
|
2020-08-08 07:10:03 +02:00
|
|
|
// FIXME: The following should have a containerOutOfBounds suppression #9242
|
|
|
|
(void)qstringlist3[3];
|
2019-08-15 10:23:05 +02:00
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringlist3.startsWith("one");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringlist3.endsWith("one");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringlist3.count();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringlist3.length();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringlist3.size();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringlist3.at(5);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)qstringlist3.at(-5);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList::iterator QStringList2()
|
|
|
|
{
|
|
|
|
QStringList qstringlist1;
|
|
|
|
QStringList qstringlist2;
|
2019-12-25 09:32:50 +01:00
|
|
|
// cppcheck-suppress mismatchingContainers
|
2019-08-15 10:23:05 +02:00
|
|
|
for (QStringList::iterator it = qstringlist1.begin(); it != qstringlist2.end(); ++it)
|
|
|
|
{}
|
|
|
|
|
|
|
|
QStringList::iterator it = qstringlist1.begin();
|
|
|
|
// cppcheck-suppress returnDanglingLifetime
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:58:55 +02:00
|
|
|
void QVector1(QVector<int> intVectorArg)
|
|
|
|
{
|
|
|
|
for (int i = 0; i <= intVectorArg.size(); ++i) {
|
|
|
|
// cppcheck-suppress stlOutOfBounds
|
|
|
|
intVectorArg[i] = 1;
|
|
|
|
}
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
intVectorArg[intVectorArg.length()] = 5;
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
intVectorArg[intVectorArg.count()] = 10;
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
printf("val: %d\n", intVectorArg[intVectorArg.size()]);
|
|
|
|
|
|
|
|
QVector<QString> qstringVector1{"one", "two"};
|
|
|
|
(void)qstringVector1[1];
|
|
|
|
|
|
|
|
QVector<QString> qstringVector2 = {"one", "two"};
|
|
|
|
(void)qstringVector2[1];
|
|
|
|
|
|
|
|
QVector<QString> qstringVector3;
|
|
|
|
qstringVector3 << "one" << "two";
|
2019-08-15 10:23:05 +02:00
|
|
|
(void)qstringVector3[1];
|
2020-08-08 07:10:03 +02:00
|
|
|
// FIXME: The following should have a containerOutOfBounds suppression #9242
|
|
|
|
(void)qstringVector3[3];
|
2019-07-31 13:58:55 +02:00
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringVector3.startsWith("one");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringVector3.endsWith("one");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringVector3.count();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringVector3.length();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringVector3.size();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringVector3.at(5);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)qstringVector3.at(-5);
|
|
|
|
}
|
|
|
|
|
2019-08-15 10:23:05 +02:00
|
|
|
QVector<int>::iterator QVector2()
|
|
|
|
{
|
|
|
|
QVector<int> qvector1;
|
|
|
|
QVector<int> qvector2;
|
2019-12-25 09:32:50 +01:00
|
|
|
// cppcheck-suppress mismatchingContainers
|
2019-08-15 10:23:05 +02:00
|
|
|
for (QVector<int>::iterator it = qvector1.begin(); it != qvector2.end(); ++it)
|
|
|
|
{}
|
|
|
|
|
|
|
|
QVector<int>::iterator it = qvector1.begin();
|
2019-12-25 09:32:50 +01:00
|
|
|
// cppcheck-suppress returnDanglingLifetime
|
2019-08-15 10:23:05 +02:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2022-01-18 20:17:05 +01:00
|
|
|
// cppcheck-suppress passedByValue
|
2021-09-17 19:46:46 +02:00
|
|
|
void duplicateExpression_QString_Compare(QString style) //#8723
|
|
|
|
{
|
2021-09-20 11:39:04 +02:00
|
|
|
// cppcheck-suppress duplicateExpression
|
2021-09-17 19:46:46 +02:00
|
|
|
if (style.compare( "x", Qt::CaseInsensitive ) == 0 || style.compare( "x", Qt::CaseInsensitive ) == 0)
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
|
2019-08-20 20:37:52 +02:00
|
|
|
void QStack1(QStack<int> intStackArg)
|
|
|
|
{
|
|
|
|
for (int i = 0; i <= intStackArg.size(); ++i) {
|
|
|
|
// cppcheck-suppress stlOutOfBounds
|
|
|
|
intStackArg[i] = 1;
|
|
|
|
}
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
intStackArg[intStackArg.length()] = 5;
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
intStackArg[intStackArg.count()] = 10;
|
|
|
|
// cppcheck-suppress containerOutOfBoundsIndexExpression
|
|
|
|
printf("val: %d\n", intStackArg[intStackArg.size()]);
|
|
|
|
|
|
|
|
QStack<QString> qstringStack1;
|
|
|
|
qstringStack1.push("one");
|
|
|
|
qstringStack1.push("two");
|
|
|
|
(void)qstringStack1[1];
|
|
|
|
|
|
|
|
QStack<QString> qstringStack2;
|
|
|
|
qstringStack2 << "one" << "two";
|
|
|
|
(void)qstringStack2[1];
|
2020-08-08 07:10:03 +02:00
|
|
|
// FIXME: The following should have a containerOutOfBounds suppression #9242
|
|
|
|
(void)qstringStack2[3];
|
2019-08-20 20:37:52 +02:00
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringStack2.startsWith("one");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringStack2.endsWith("one");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringStack2.count();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringStack2.length();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringStack2.size();
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
qstringStack2.at(5);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)qstringStack2.at(-5);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStack<int>::iterator QStack2()
|
|
|
|
{
|
|
|
|
QStack<int> qstack1;
|
|
|
|
QStack<int> qstack2;
|
2019-12-25 09:32:50 +01:00
|
|
|
// cppcheck-suppress mismatchingContainers
|
2019-08-20 20:37:52 +02:00
|
|
|
for (QStack<int>::iterator it = qstack1.begin(); it != qstack2.end(); ++it)
|
|
|
|
{}
|
|
|
|
|
|
|
|
QStack<int>::iterator it = qstack1.begin();
|
2019-12-25 09:32:50 +01:00
|
|
|
// cppcheck-suppress returnDanglingLifetime
|
2019-08-20 20:37:52 +02:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QStack3()
|
|
|
|
{
|
|
|
|
QStack<int> intStack;
|
|
|
|
intStack.push(1);
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
intStack.top();
|
|
|
|
intStack.pop();
|
|
|
|
}
|
|
|
|
|
2019-01-07 14:40:21 +01:00
|
|
|
// Verify that Qt macros do not result in syntax errors, false positives or other issues.
|
2021-08-07 20:51:18 +02:00
|
|
|
class MacroTest1 : public QObject {
|
2019-01-07 14:40:21 +01:00
|
|
|
Q_OBJECT
|
|
|
|
Q_PLUGIN_METADATA(IID "com.foo.bar" FILE "test.json")
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit MacroTest1(QObject *parent = 0);
|
|
|
|
~MacroTest1();
|
|
|
|
};
|
2019-02-06 13:23:05 +01:00
|
|
|
|
2019-02-26 13:39:37 +01:00
|
|
|
class MacroTest2 {
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(MacroTest2)
|
|
|
|
|
|
|
|
public:
|
|
|
|
MacroTest2();
|
|
|
|
~MacroTest2();
|
|
|
|
};
|
|
|
|
|
|
|
|
void MacroTest2_test()
|
|
|
|
{
|
|
|
|
QString str = MacroTest2::tr("hello");
|
|
|
|
QByteArray ba = str.toLatin1();
|
|
|
|
printf(ba.data());
|
|
|
|
|
|
|
|
#ifndef QT_NO_DEPRECATED
|
|
|
|
str = MacroTest2::trUtf8("test2");
|
|
|
|
ba = str.toLatin1();
|
|
|
|
printf(ba.data());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-01-07 23:29:47 +01:00
|
|
|
void MacroTest3()
|
|
|
|
{
|
|
|
|
QByteArray message = QByteArrayLiteral("Test1");
|
|
|
|
message += QByteArrayLiteral("Test2");
|
|
|
|
QVERIFY2(2 >= 0, message.constData());
|
|
|
|
}
|
|
|
|
|
2023-04-01 16:33:50 +02:00
|
|
|
void validCode(int * pIntPtr, QString & qstrArg, double d)
|
2019-02-06 13:23:05 +01:00
|
|
|
{
|
2023-04-01 16:33:50 +02:00
|
|
|
Q_UNUSED(d)
|
2021-08-07 20:51:18 +02:00
|
|
|
if (QFile::exists("test")) {}
|
2019-02-07 12:27:25 +01:00
|
|
|
|
|
|
|
if (pIntPtr != Q_NULLPTR) {
|
|
|
|
*pIntPtr = 5;
|
|
|
|
}
|
2019-02-11 16:35:01 +01:00
|
|
|
|
|
|
|
if (pIntPtr && *pIntPtr == 1) {
|
|
|
|
forever {
|
|
|
|
}
|
|
|
|
} else if (pIntPtr && *pIntPtr == 2) {
|
2021-08-07 20:51:18 +02:00
|
|
|
Q_FOREVER {}
|
2019-02-11 16:35:01 +01:00
|
|
|
}
|
2019-02-12 08:21:49 +01:00
|
|
|
|
|
|
|
if (Q_LIKELY(pIntPtr)) {}
|
|
|
|
if (Q_UNLIKELY(!pIntPtr)) {}
|
2019-02-12 10:21:56 +01:00
|
|
|
|
|
|
|
printf(QT_TR_NOOP("Hi"));
|
2019-09-16 15:58:35 +02:00
|
|
|
|
|
|
|
Q_DECLARE_LOGGING_CATEGORY(logging_category_test);
|
|
|
|
QT_FORWARD_DECLARE_CLASS(forwardDeclaredClass);
|
|
|
|
QT_FORWARD_DECLARE_STRUCT(forwardDeclaredStruct);
|
2020-02-26 10:53:03 +01:00
|
|
|
|
|
|
|
//#9650
|
|
|
|
QString qstr1(qstrArg);
|
2021-08-07 20:51:18 +02:00
|
|
|
if (qstr1.length() == 1) {} else {
|
2020-02-26 10:53:03 +01:00
|
|
|
qstr1.chop(1);
|
|
|
|
if (qstr1.length() == 1) {}
|
|
|
|
}
|
2021-08-07 20:51:18 +02:00
|
|
|
if (qstr1.length() == 1) {} else {
|
2020-02-26 10:53:03 +01:00
|
|
|
qstr1.remove(1);
|
|
|
|
if (qstr1.length() == 1) {}
|
|
|
|
}
|
2019-02-06 13:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ignoredReturnValue()
|
|
|
|
{
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
QFile::exists("test");
|
|
|
|
QFile file1("test");
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
file1.exists();
|
|
|
|
}
|
2019-02-07 12:27:25 +01:00
|
|
|
|
|
|
|
void nullPointer(int * pIntPtr)
|
|
|
|
{
|
|
|
|
int * pNullPtr = Q_NULLPTR;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
*pNullPtr = 1;
|
|
|
|
|
|
|
|
if (pIntPtr != Q_NULLPTR) {
|
|
|
|
*pIntPtr = 2;
|
|
|
|
} else {
|
|
|
|
// cppcheck-suppress nullPointerRedundantCheck
|
|
|
|
*pIntPtr = 3;
|
|
|
|
}
|
|
|
|
}
|
2022-07-13 21:09:53 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
class C : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit C(QObject* parent = nullptr) : QObject(parent) {}
|
|
|
|
void signal() {}
|
|
|
|
};
|
|
|
|
class D : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
D() {
|
|
|
|
connect(new C(this), &C::signal, this, &D::slot);
|
|
|
|
}
|
|
|
|
void slot() {};
|
|
|
|
};
|
2023-02-25 15:58:57 +01:00
|
|
|
|
|
|
|
// findFunction11
|
|
|
|
class Fred : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
|
|
void foo();
|
|
|
|
};
|
2023-03-07 17:57:51 +01:00
|
|
|
void Fred::foo() {}
|
2023-02-25 15:58:57 +01:00
|
|
|
|
|
|
|
// bitfields14
|
|
|
|
class X {
|
|
|
|
signals:
|
|
|
|
};
|
|
|
|
|
|
|
|
// simplifyQtSignalsSlots1
|
|
|
|
class Counter1 : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-03-07 17:57:51 +01:00
|
|
|
Counter1() {
|
|
|
|
m_value = 0;
|
|
|
|
}
|
|
|
|
int value() const {
|
|
|
|
return m_value;
|
|
|
|
}
|
2023-02-25 15:58:57 +01:00
|
|
|
public slots:
|
|
|
|
void setValue(int value);
|
|
|
|
signals:
|
|
|
|
void valueChanged(int newValue);
|
|
|
|
private:
|
|
|
|
int m_value;
|
|
|
|
};
|
|
|
|
void Counter1::setValue(int value) {
|
|
|
|
if (value != m_value) {
|
|
|
|
m_value = value;
|
|
|
|
emit valueChanged(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Counter2 : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-03-07 17:57:51 +01:00
|
|
|
Counter2() {
|
|
|
|
m_value = 0;
|
|
|
|
}
|
|
|
|
int value() const {
|
|
|
|
return m_value;
|
|
|
|
}
|
2023-02-25 15:58:57 +01:00
|
|
|
public Q_SLOTS:
|
|
|
|
void setValue(int value);
|
|
|
|
Q_SIGNALS:
|
|
|
|
void valueChanged(int newValue);
|
|
|
|
private:
|
|
|
|
int m_value;
|
|
|
|
};
|
|
|
|
void Counter2::setValue(int value) {
|
|
|
|
if (value != m_value) {
|
|
|
|
m_value = value;
|
|
|
|
emit valueChanged(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyObject1 : public QObject {
|
|
|
|
MyObject1() {}
|
|
|
|
~MyObject1() {}
|
|
|
|
public slots:
|
|
|
|
signals:
|
|
|
|
void test() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MyObject2 : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public slots:
|
|
|
|
};
|
|
|
|
|
|
|
|
// simplifyQtSignalsSlots2
|
|
|
|
namespace Foo { class Bar; }
|
|
|
|
class Foo::Bar : public QObject { private slots: };
|
2022-07-13 21:09:53 +02:00
|
|
|
}
|