aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2019-06-03 17:32:35 +0100
committerSergio Martins <smartins@kde.org>2019-06-03 17:32:35 +0100
commit04d096386a149f09156ce78f0803f08cde8095b0 (patch)
tree9f8071d9d84514f2168103e60fa8c5fbe39af9bb
parent7763c1d33ea68a02b3db44feb2cd2b5bdb154bf0 (diff)
signal-with-return-value: warn for by-ref signal arguments
For the same reason as return values
-rw-r--r--src/checks/manuallevel/signal-with-return-value.cpp12
-rw-r--r--tests/signal-with-return-value/main.cpp5
2 files changed, 13 insertions, 4 deletions
diff --git a/src/checks/manuallevel/signal-with-return-value.cpp b/src/checks/manuallevel/signal-with-return-value.cpp
index 25884374..9c52079e 100644
--- a/src/checks/manuallevel/signal-with-return-value.cpp
+++ b/src/checks/manuallevel/signal-with-return-value.cpp
@@ -50,12 +50,16 @@ void SignalWithReturnValue::VisitDecl(clang::Decl *decl)
return;
const bool methodIsSignal = accessSpecifierManager->qtAccessSpecifierType(method) == QtAccessSpecifier_Signal;
- if (!methodIsSignal)
+ if (!methodIsSignal || accessSpecifierManager->isScriptable(method))
return;
- if (!method->getReturnType()->isVoidType()) {
- if (!accessSpecifierManager->isScriptable(method)) {
- emitWarning(decl, std::string(clazy::name(method)) + "() should return void. For a clean design signals shouldn't assume a single slot are connected to them.");
+ if (!method->getReturnType()->isVoidType())
+ emitWarning(decl, std::string(clazy::name(method)) + "() should return void. For a clean design signals shouldn't assume a single slot are connected to them.");
+
+ for (auto param : method->parameters()) {
+ QualType qt = param->getType();
+ if (qt->isReferenceType() && !qt->getPointeeType().isConstQualified()) {
+ emitWarning(decl, std::string(clazy::name(method)) + "() shouldn't receive parameters by ref. For a clean design signals shouldn't assume a single slot are connected to them.");
}
}
}
diff --git a/tests/signal-with-return-value/main.cpp b/tests/signal-with-return-value/main.cpp
index 19a7c113..ad43c595 100644
--- a/tests/signal-with-return-value/main.cpp
+++ b/tests/signal-with-return-value/main.cpp
@@ -9,5 +9,10 @@ signals:
int intSig(); // Warn
void* voidStarSig(); // warn
Q_SCRIPTABLE int scriptableIntSig(); // ok
+
+ void withArgs1(const Foo f); // OK
+ void withArgs2(const Foo &f); // OK
+ void withArgs3(Foo f); // OK
+ void withArgs4(Foo &f); // Warn
};