aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2019-10-01 18:23:20 +0100
committerSergio Martins <smartins@kde.org>2019-10-01 18:23:20 +0100
commit492c3a6e1011a5cd07e9580a0b42eaaa62f48096 (patch)
tree1521f896057d7c460591b3455bb88deb61b8916a /src
parentf8a1d3050c55cdf803a83a7f9fda7652370a4352 (diff)
qproperty-type-mismatch: Fix more false-positives with typedefs
Typedefs from system headers (such as Qt) were being ignored
Diffstat (limited to 'src')
-rw-r--r--src/checks/manuallevel/qproperty-type-mismatch.cpp21
-rw-r--r--src/checks/manuallevel/qproperty-type-mismatch.h4
2 files changed, 14 insertions, 11 deletions
diff --git a/src/checks/manuallevel/qproperty-type-mismatch.cpp b/src/checks/manuallevel/qproperty-type-mismatch.cpp
index 7dc312ce..20dd382f 100644
--- a/src/checks/manuallevel/qproperty-type-mismatch.cpp
+++ b/src/checks/manuallevel/qproperty-type-mismatch.cpp
@@ -56,6 +56,7 @@ QPropertyTypeMismatch::QPropertyTypeMismatch(const std::string &name, ClazyConte
: CheckBase(name, context)
{
enablePreProcessorCallbacks();
+ context->enableVisitallTypeDefs();
}
void QPropertyTypeMismatch::VisitDecl(clang::Decl *decl)
@@ -64,8 +65,8 @@ void QPropertyTypeMismatch::VisitDecl(clang::Decl *decl)
VisitMethod(*method);
else if (auto field = dyn_cast<FieldDecl>(decl))
VisitField(*field);
- else if (auto typedefdecl = dyn_cast<TypedefDecl>(decl))
- VisitTypedef(*typedefdecl);
+ else if (auto typedefdecl = dyn_cast<TypedefNameDecl>(decl))
+ VisitTypedef(typedefdecl);
}
void QPropertyTypeMismatch::VisitMethod(const clang::CXXMethodDecl & method)
@@ -101,12 +102,12 @@ void QPropertyTypeMismatch::VisitField(const FieldDecl & field)
}
}
-void QPropertyTypeMismatch::VisitTypedef(const TypedefDecl &td)
+void QPropertyTypeMismatch::VisitTypedef(const clang::TypedefNameDecl *td)
{
// Since when processing Q_PROPERTY we're at the pre-processor stage we don't have access
// to the Qualtypes, so catch any typedefs here
- QualType underlyingType = td.getUnderlyingType();
- m_typedefMap[td.getNameAsString()] = underlyingType;
+ QualType underlyingType = td->getUnderlyingType();
+ m_typedefMap[td->getQualifiedNameAsString()] = underlyingType;
}
std::string QPropertyTypeMismatch::cleanupType(QualType type, bool unscoped) const
@@ -208,17 +209,17 @@ bool QPropertyTypeMismatch::typesMatch(const string &type1, QualType type2Qt, st
if (type1 == type2Cleaned)
return true;
- // Maybe the difference is just the scope, if yes then don't warn. We already have a check for complaining about lack of scope
- type2Cleaned = cleanupType(type2Qt, /*unscopped=*/ true);
- if (type1 == type2Cleaned)
- return true;
-
// Maybe it's a typedef
auto it = m_typedefMap.find(type1);
if (it != m_typedefMap.cend()) {
return it->second == type2Qt || cleanupType(it->second) == type2Cleaned;
}
+ // Maybe the difference is just the scope, if yes then don't warn. We already have a check for complaining about lack of scope
+ type2Cleaned = cleanupType(type2Qt, /*unscopped=*/ true);
+ if (type1 == type2Cleaned)
+ return true;
+
return false;
}
diff --git a/src/checks/manuallevel/qproperty-type-mismatch.h b/src/checks/manuallevel/qproperty-type-mismatch.h
index 1099d876..573083b2 100644
--- a/src/checks/manuallevel/qproperty-type-mismatch.h
+++ b/src/checks/manuallevel/qproperty-type-mismatch.h
@@ -37,6 +37,7 @@ class FieldDecl;
class Decl;
class MacroInfo;
class Token;
+class TypeAliasDecl;
} // namespace clang
/**
@@ -51,7 +52,8 @@ public:
private:
void VisitMethod(const clang::CXXMethodDecl &);
void VisitField(const clang::FieldDecl &);
- void VisitTypedef(const clang::TypedefDecl &);
+ void VisitTypedef(const clang::TypedefNameDecl *);
+
void VisitMacroExpands(const clang::Token &MacroNameTok,
const clang::SourceRange &range, const clang::MacroInfo *minfo = nullptr) override;