summaryrefslogtreecommitdiffstats
path: root/compilerplugins/clang/redundantcast.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-06-01 14:37:02 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-06-01 14:37:02 +0200
commit93aeaa75a4bfd5756b2d3ada59be4f452e320aab (patch)
tree582afb0b96fb677629e06c271aa4914ec0870ccc /compilerplugins/clang/redundantcast.cxx
parentuse std::vector in OListAndComboImport (diff)
downloadcore-93aeaa75a4bfd5756b2d3ada59be4f452e320aab.tar.gz
core-93aeaa75a4bfd5756b2d3ada59be4f452e320aab.zip
Improve suppression of loplugin:redundantcast in CPPUNIT_ASSERT
Change-Id: I65f95e7245f08592ea11cc75e1cf34dcbdf16b40
Diffstat (limited to 'compilerplugins/clang/redundantcast.cxx')
-rw-r--r--compilerplugins/clang/redundantcast.cxx42
1 files changed, 11 insertions, 31 deletions
diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx
index 2c9a6fa49c89..de3353b295c1 100644
--- a/compilerplugins/clang/redundantcast.cxx
+++ b/compilerplugins/clang/redundantcast.cxx
@@ -456,37 +456,6 @@ bool RedundantCast::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const * exp
if (ignoreLocation(expr)) {
return true;
}
- // A bit of a rabbit hole here, these expressions look like
- // CPPUNIT_ASSERT( bool(aVec.find(p1.get()) == aVec.end()) )
- // If I remove the bool, then another plugin wants me to change it to CPPUNIT_ASSERT_EQUAL,
- // but that fails because CppUnit can't do "std::ostream << iterator".
- StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(expr->getLocStart()));
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/o3tl/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sfx2/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/postprocess/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sc/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/cppu/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/vcl/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/cppuhelper/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/comphelper/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/connectivity/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sal/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/salhelper/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sw/qa/"))
- return true;
- if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/svl/qa/"))
- return true;
// Restrict this to "real" casts (compared to uses of braced-init-list, like
//
@@ -502,6 +471,17 @@ bool RedundantCast::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const * exp
return true;
}
+ // See "There might even be good reasons(?) not to warn inside explicit
+ // casts" block in compilerplugins/clang/test/cppunitassertequals.cxx:
+ auto const eloc = expr->getExprLoc();
+ if (compiler.getSourceManager().isMacroArgExpansion(eloc)) {
+ auto const name = Lexer::getImmediateMacroName(
+ eloc, compiler.getSourceManager(), compiler.getLangOpts());
+ if (name == "CPPUNIT_ASSERT" || name == "CPPUNIT_ASSERT_MESSAGE") {
+ return true;
+ }
+ }
+
// See the commit message of d0e7d020fa405ab94f19916ec96fbd4611da0031
// "socket.c -> socket.cxx" for the reason to have
//