diff options
author | Sergio Martins <smartins@kde.org> | 2017-05-01 21:03:29 +0100 |
---|---|---|
committer | Sergio Martins <smartins@kde.org> | 2017-06-03 13:46:20 +0100 |
commit | 7104e18f04369960e1bf86d97e7669eb243e2130 (patch) | |
tree | f4b300e3a4da11da9a5b61e8a2ce3860a98b4b06 /tests/connect-not-normalized | |
parent | 72ba4eea485a5ce1b9a2732dc6ed9b1d548c3c93 (diff) |
Introducing connect-not-normalized
Warns when finding non-normalized SIGNAL/SLOT/Q_ARG and Q_RETURN_ARG, which
cause unneeded temporary memory allocations.
Idea by the Gammaray guys.
CCMAIL: volker.krause@kdab.com
Diffstat (limited to 'tests/connect-not-normalized')
-rw-r--r-- | tests/connect-not-normalized/config.json | 7 | ||||
-rw-r--r-- | tests/connect-not-normalized/main.cpp | 32 | ||||
-rw-r--r-- | tests/connect-not-normalized/main.cpp.expected | 6 |
3 files changed, 45 insertions, 0 deletions
diff --git a/tests/connect-not-normalized/config.json b/tests/connect-not-normalized/config.json new file mode 100644 index 00000000..e7e6e0cb --- /dev/null +++ b/tests/connect-not-normalized/config.json @@ -0,0 +1,7 @@ +{ + "tests" : [ + { + "filename" : "main.cpp" + } + ] +} diff --git a/tests/connect-not-normalized/main.cpp b/tests/connect-not-normalized/main.cpp new file mode 100644 index 00000000..5beceafb --- /dev/null +++ b/tests/connect-not-normalized/main.cpp @@ -0,0 +1,32 @@ +#include <QtCore/QObject> +#include <QtCore/QVariant> + +void test() +{ + QObject o; + + QVariant v, returnedValue; + QMetaObject::invokeMethod(&o, "mySlot", + Q_RETURN_ARG(QVariant, returnedValue), // OK + Q_ARG(const QVariant, v)); // Warn + QMetaObject::invokeMethod(&o, "mySlot", + Q_RETURN_ARG(QVariant, returnedValue), // OK + Q_ARG(const QVariant, // Warn + v)); // multi-line + + Q_ARG(QVariant , v); // OK + Q_ARG(QVariant &, v); // Warn + Q_ARG(QVariant&, v); // OK + Q_ARG(const QVariant &, v); // Warn +} + +void testConnect() +{ + QObject o; + o.connect(&o, SIGNAL(destroyed(int, int)), // Warn + &o, SLOT(void foo(const int))); // Warn + o.connect(&o, SIGNAL(destroyed(int,int)), // OK + &o, SLOT(void foo(int))); // OK + + o.disconnect(&o, SLOT(void foo(const int))); // OK +} diff --git a/tests/connect-not-normalized/main.cpp.expected b/tests/connect-not-normalized/main.cpp.expected new file mode 100644 index 00000000..1120e8fa --- /dev/null +++ b/tests/connect-not-normalized/main.cpp.expected @@ -0,0 +1,6 @@ +connect-not-normalized/main.cpp:11:31: warning: Signature is not normalized. Use QVariant instead of const QVariant [-Wclazy-connect-not-normalized] +connect-not-normalized/main.cpp:14:31: warning: Signature is not normalized. Use QVariant instead of const QVariant [-Wclazy-connect-not-normalized] +connect-not-normalized/main.cpp:18:5: warning: Signature is not normalized. Use QVariant& instead of QVariant & [-Wclazy-connect-not-normalized] +connect-not-normalized/main.cpp:20:5: warning: Signature is not normalized. Use QVariant instead of const QVariant & [-Wclazy-connect-not-normalized] +connect-not-normalized/main.cpp:26:19: warning: Signature is not normalized. Use destroyed(int,int) instead of destroyed(int, int) +connect-not-normalized/main.cpp:27:19: warning: Signature is not normalized. Use void foo(int) instead of void foo(const int) |