diff options
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/redundantcast.cxx | 3 | ||||
-rw-r--r-- | compilerplugins/clang/test/redundantcast.cxx | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx index 19393e0c64490..32f7e8bd7fd9f 100644 --- a/compilerplugins/clang/redundantcast.cxx +++ b/compilerplugins/clang/redundantcast.cxx @@ -294,6 +294,9 @@ bool RedundantCast::VisitCStyleCastExpr(CStyleCastExpr const * expr) { } auto t1 = compat::getSubExprAsWritten(expr)->getType(); auto t2 = expr->getTypeAsWritten(); + if (auto templateType = dyn_cast<SubstTemplateTypeParmType>(t1)) { + t1 = templateType->desugar(); + } if (t1 != t2) { return true; } diff --git a/compilerplugins/clang/test/redundantcast.cxx b/compilerplugins/clang/test/redundantcast.cxx index 9eda22a04b0f3..db1268b8b87ba 100644 --- a/compilerplugins/clang/test/redundantcast.cxx +++ b/compilerplugins/clang/test/redundantcast.cxx @@ -290,11 +290,23 @@ void testCStyleCast() { (void)e; } +template<typename T> +struct EnumItemInterface { + T GetValue() { return static_cast<T>(0); } +}; +class Enum1Item : public EnumItemInterface<Enum1> { +}; +bool testCStyleCastOfTemplateMethodResult(Enum1Item* item) { + return (Enum1)item->GetValue() == Enum1::X; // expected-error {{redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]}} +} + + int main() { testConstCast(); testStaticCast(); testFunctionalCast(); testCStyleCast(); + testCStyleCastOfTemplateMethodResult(nullptr); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |