loplugin:redundantcast find redundant c-style enum casts
Change-Id: I2dab376d87804521aed6b6bd41ad7762830fa349 Reviewed-on: https://gerrit.libreoffice.org/35467 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -138,6 +138,8 @@ public:
|
||||
|
||||
bool VisitCXXDeleteExpr(CXXDeleteExpr const * expr);
|
||||
|
||||
bool VisitCStyleCastExpr(CStyleCastExpr const * expr);
|
||||
|
||||
bool VisitBinSub(BinaryOperator const * expr)
|
||||
{ return visitBinOp(expr); }
|
||||
|
||||
@@ -288,6 +290,24 @@ bool RedundantCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RedundantCast::VisitCStyleCastExpr(CStyleCastExpr const * expr) {
|
||||
if (ignoreLocation(expr)) {
|
||||
return true;
|
||||
}
|
||||
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(expr->getLocStart()))) {
|
||||
return true;
|
||||
}
|
||||
auto t1 = getSubExprAsWritten(expr)->getType();
|
||||
auto t2 = expr->getTypeAsWritten();
|
||||
if (loplugin::TypeCheck(t1).Enum() && loplugin::TypeCheck(t2).Enum() && t1 == t2) {
|
||||
report(
|
||||
DiagnosticsEngine::Warning,
|
||||
"redundant cstyle enum cast from %0 to %1", expr->getExprLoc())
|
||||
<< t1 << t2 << expr->getSourceRange();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RedundantCast::VisitCXXStaticCastExpr(CXXStaticCastExpr const * expr) {
|
||||
if (ignoreLocation(expr)) {
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user