aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2019-09-29 21:36:48 +0100
committerSergio Martins <smartins@kde.org>2019-09-29 21:36:48 +0100
commit5e3eb5554cd31f0c0a9e205e7ec47139900a6b0e (patch)
tree728507fd4b6afc4f28c5f7a8da5b8b6bd1ebc095 /src
parentb90dc89695350b2f0eb2872b414cb44f0c1b1671 (diff)
qproperty-type-mismatch: Fix false positive
When using inner classes as Q_PROPERTY
Diffstat (limited to 'src')
-rw-r--r--src/checks/manuallevel/qproperty-type-mismatch.cpp15
-rw-r--r--src/checks/manuallevel/qproperty-type-mismatch.h2
2 files changed, 10 insertions, 7 deletions
diff --git a/src/checks/manuallevel/qproperty-type-mismatch.cpp b/src/checks/manuallevel/qproperty-type-mismatch.cpp
index a0e29002..c0c1c342 100644
--- a/src/checks/manuallevel/qproperty-type-mismatch.cpp
+++ b/src/checks/manuallevel/qproperty-type-mismatch.cpp
@@ -99,11 +99,13 @@ void QPropertyTypeMismatch::VisitField(const FieldDecl & field)
}
}
-std::string QPropertyTypeMismatch::cleanupType(QualType type) {
+std::string QPropertyTypeMismatch::cleanupType(QualType type, bool unscoped)
+{
type = type.getNonReferenceType().getCanonicalType().getUnqualifiedType();
PrintingPolicy po(lo());
po.SuppressTagKeyword = true;
+ po.SuppressScope = unscoped;
std::string str = type.getAsString(po);
str.erase(std::remove_if(str.begin(), str.end(), [] (char c) { return std::isspace(c); }), str.end());
@@ -114,12 +116,13 @@ void QPropertyTypeMismatch::checkMethodAgainstProperty (const Property& prop, co
auto error_begin = [&] { return "Q_PROPERTY '" + prop.name + "' of type '" + prop.type + "' is mismatched with "; };
- if(prop.read == methodName)
- {
+ if (prop.read == methodName) {
auto retTypeStr = cleanupType(method.getReturnType());
- if(prop.type != retTypeStr)
- {
- emitWarning(&method, error_begin() + "method '" + methodName + "' of return type '"+ retTypeStr +"'");
+ if (prop.type != retTypeStr) {
+ // Maybe the difference is just the scope, if yes then don't warn. We already have a check for complaining about lack of scope
+ auto retTypeStrUnscopped = cleanupType(method.getReturnType(), /*unscopped=*/ true);
+ if (prop.type != retTypeStrUnscopped)
+ emitWarning(&method, error_begin() + "method '" + methodName + "' of return type '"+ retTypeStr +"'");
}
}
else if(prop.write == methodName)
diff --git a/src/checks/manuallevel/qproperty-type-mismatch.h b/src/checks/manuallevel/qproperty-type-mismatch.h
index e0e40868..ce80900c 100644
--- a/src/checks/manuallevel/qproperty-type-mismatch.h
+++ b/src/checks/manuallevel/qproperty-type-mismatch.h
@@ -65,7 +65,7 @@ private:
};
std::vector<Property> m_qproperties;
- std::string cleanupType(clang::QualType type);
+ std::string cleanupType(clang::QualType type, bool unscoped = false);
void checkMethodAgainstProperty(const Property &prop, const clang::CXXMethodDecl &method, const std::string &methodName);
void checkFieldAgainstProperty(const Property &prop, const clang::FieldDecl &method, const std::string &methodName);
};