diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-12-18 13:52:04 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-12-18 22:43:26 +0100 |
commit | 0f22790e6bc936b6de588c30816d6fa59f4a14dc (patch) | |
tree | 8c845be4b234748af298c62f5ef2f0f120ef4e0b /compilerplugins/clang/redundantcast.cxx | |
parent | Rename cdecl -> classdecl (MSVC treats the former like a keyword) (diff) | |
download | core-0f22790e6bc936b6de588c30816d6fa59f4a14dc.tar.gz core-0f22790e6bc936b6de588c30816d6fa59f4a14dc.zip |
Generalize typedef-to-void* check in loplugin:redundantcast
...to also cover cases like conversion betwen LPVOID and HANDLE in Windows-only
code
Change-Id: I934fe89372ee7a12462e7ad4284b9ea2cc73ce5a
Diffstat (limited to 'compilerplugins/clang/redundantcast.cxx')
-rw-r--r-- | compilerplugins/clang/redundantcast.cxx | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx index 5215b39b18e5..6d18f2abffd8 100644 --- a/compilerplugins/clang/redundantcast.cxx +++ b/compilerplugins/clang/redundantcast.cxx @@ -291,29 +291,36 @@ bool RedundantCast::VisitCXXStaticCastExpr(CXXStaticCastExpr const * expr) { { return true; } - // Don't warn about - // - // *pResult = static_cast<oslModule>(RTLD_DEFAULT); - // - // in osl_getModuleHandle (sal/osl/unx/module.cxx) (where oslModule is a - // typedef to void *): - if (loplugin::TypeCheck(t2).Typedef("oslModule").GlobalNamespace() - && !loplugin::TypeCheck(t1).Typedef()) - { - return true; - } - // Dont't warn about - // - // curl_easy_setopt(static_cast<CURL*>(pData), - // CURLOPT_HEADERFUNCTION, - // memory_write_dummy); - // - // in delete_CURL (ucb/source/ucp/ftp/ftploaderthread.cxx) (where CURL is a - // typedef to void): - if (loplugin::TypeCheck(t2).Pointer().Typedef("CURL").GlobalNamespace() - && !loplugin::TypeCheck(t1).Pointer().Typedef()) - { - return true; + // Don't warn if the types are 'void *' and at least one involves a typedef + // (and if both involve typedefs, they're different) (this covers cases like + // 'oslModule', or 'CURL *', or casts between 'LPVOID' and 'HANDLE' in + // Windows-only code): + if (loplugin::TypeCheck(t1).Pointer().NonConstVolatile().Void()) { + if (auto const td1 = t1->getAs<TypedefType>()) { + auto const td2 = t2->getAs<TypedefType>(); + if (td2 == nullptr || td2 != td1) { + return true; + } + } else if (auto const td2 = t2->getAs<TypedefType>()) { + auto const td1 = t1->getAs<TypedefType>(); + if (td1 == nullptr || td1 != td2) { + return true; + } + } else { + auto const pt1 = t1->getAs<clang::PointerType>()->getPointeeType(); + auto const pt2 = t2->getAs<clang::PointerType>()->getPointeeType(); + if (auto const ptd1 = pt1->getAs<TypedefType>()) { + auto const ptd2 = pt2->getAs<TypedefType>(); + if (ptd2 == nullptr || ptd2 != ptd1) { + return true; + } + } else if (auto const ptd2 = pt2->getAs<TypedefType>()) { + auto const ptd1 = pt1->getAs<TypedefType>(); + if (ptd1 == nullptr || ptd1 != ptd2) { + return true; + } + } + } } report( DiagnosticsEngine::Warning, |