diff options
author | Sergio Martins <smartins@kde.org> | 2017-11-08 13:02:33 +0000 |
---|---|---|
committer | Sergio Martins <iamsergio@gmail.com> | 2017-11-08 13:15:56 +0000 |
commit | e77b0e16f88c7b7b08aa1d6972d439620f1c7462 (patch) | |
tree | e4b7693de141904b63c99c0d8996a884731c28ef /src | |
parent | 87f239cd9fcf9b4603e3ea8e00df5dcd7c1bd477 (diff) |
old-style-connect: Fix fixit bug when using Q_PRIVATE_SLOT
If the QObject has a signal with the same name of a Q_PRIVATE_SLOT
then the fixit would connect to the signal instead of the private
slot.
The fix is generic, if the user used the SLOT macro we simply
never rewrite to use a signal.
CCMAIL: dfaure@kdab.com
Diffstat (limited to 'src')
-rw-r--r-- | src/checks/level2/oldstyleconnect.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/checks/level2/oldstyleconnect.cpp b/src/checks/level2/oldstyleconnect.cpp index 18d1743b..1a4fabef 100644 --- a/src/checks/level2/oldstyleconnect.cpp +++ b/src/checks/level2/oldstyleconnect.cpp @@ -30,6 +30,8 @@ #include "FixItUtils.h" #include "ContextUtils.h" #include "QtUtils.h" +#include "ClazyContext.h" +#include "AccessSpecifierManager.h" #include <clang/AST/Decl.h> #include <clang/AST/DeclCXX.h> @@ -74,6 +76,7 @@ OldStyleConnect::OldStyleConnect(const std::string &name, ClazyContext *context) : CheckBase(name, context) { enablePreProcessorCallbacks(); + context->enableAccessSpecifierManager(); } int OldStyleConnect::classifyConnect(FunctionDecl *connectFunc, CallExpr *connectCall) @@ -175,7 +178,7 @@ bool OldStyleConnect::isPrivateSlot(const string &name) const void OldStyleConnect::VisitStmt(Stmt *s) { - CallExpr *call = dyn_cast<CallExpr>(s); + auto call = dyn_cast<CallExpr>(s); if (!call) return; @@ -186,7 +189,7 @@ void OldStyleConnect::VisitStmt(Stmt *s) if (!function) return; - CXXMethodDecl *method = dyn_cast<CXXMethodDecl>(function); + auto method = dyn_cast<CXXMethodDecl>(function); if (!method) return; @@ -331,12 +334,24 @@ vector<FixItHint> OldStyleConnect::fixits(int classification, CallExpr *call) + methodName + " for record " + lastRecordDecl->getNameAsString(); queueManualFixitWarning(s, FixItConnects, msg); return {}; + } else { + AccessSpecifierManager *a = m_context->accessSpecifierManager; + if (!a) + return {}; + + const bool isSignal = a->qtAccessSpecifierType(methods[0]) == QtAccessSpecifier_Signal; + if (isSignal && macroName == "SLOT") { + // The method is actually a signal and the user used SLOT() + // bail out with the fixing. + string msg = string("Can't fix. SLOT macro used but method " + methodName + " is a signal"); + queueManualFixitWarning(s, FixItConnects, msg); + return {}; + } } auto methodDecl = methods[0]; - if (methodDecl->isStatic()) { + if (methodDecl->isStatic()) return {}; - } if (macroNum == 1) { // Save the number of parameters of the signal. The slot should not have more arguments. |