summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-11-22 09:54:10 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-11-22 09:54:10 +0100
commit5640ef110094f33cf678f4e3ef4f3fd4334a00c8 (patch)
tree499c171c0b92750c8515c2698d93ad3e20a3291b /compilerplugins
parent1d9eed341db208f11de6f020538dfdb74a5c48dd (diff)
There appears to be no reason to ignore macros in these parts of...
...loplugin:unnecessaryparen Change-Id: I473a1e16cf9f485a61af5477aca22798996253a3
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/unnecessaryparen.cxx33
1 files changed, 11 insertions, 22 deletions
diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx
index 57c9cd9c65b4..fe3b0dd4b028 100644
--- a/compilerplugins/clang/unnecessaryparen.cxx
+++ b/compilerplugins/clang/unnecessaryparen.cxx
@@ -146,15 +146,16 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr)
}
if (auto declRefExpr = dyn_cast<DeclRefExpr>(subExpr)) {
- if (declRefExpr->getLocStart().isMacroID())
- return true;
-
- // hack for BAD_CAST macro
- SourceManager& SM = compiler.getSourceManager();
- const char *p1 = SM.getCharacterData( declRefExpr->getLocStart().getLocWithOffset(-10) );
- const char *p2 = SM.getCharacterData( declRefExpr->getLocStart() );
- if ( std::string(p1, p2 - p1).find("BAD_CAST") != std::string::npos )
- return true;
+ // hack for libxml2's BAD_CAST object-like macro (expanding to "(xmlChar *)"), which is
+ // typically used as if it were a function-like macro, e.g., as "BAD_CAST(pName)" in
+ // SwNode::dumpAsXml (sw/source/core/docnode/node.cxx)
+ if (!declRefExpr->getLocStart().isMacroID()) {
+ SourceManager& SM = compiler.getSourceManager();
+ const char *p1 = SM.getCharacterData( declRefExpr->getLocStart().getLocWithOffset(-10) );
+ const char *p2 = SM.getCharacterData( declRefExpr->getLocStart() );
+ if ( std::string(p1, p2 - p1).find("BAD_CAST") != std::string::npos )
+ return true;
+ }
report(
DiagnosticsEngine::Warning, "unnecessary parentheses around identifier",
@@ -163,9 +164,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr)
}
- if (auto cxxNamedCastExpr = dyn_cast<CXXNamedCastExpr>(subExpr)) {
- if (cxxNamedCastExpr->getLocStart().isMacroID())
- return true;
+ if (isa<CXXNamedCastExpr>(subExpr)) {
report(
DiagnosticsEngine::Warning, "unnecessary parentheses around cast",
parenExpr->getLocStart())
@@ -209,8 +208,6 @@ bool UnnecessaryParen::VisitReturnStmt(const ReturnStmt* returnStmt)
{
if (ignoreLocation(returnStmt))
return true;
- if (returnStmt->getLocStart().isMacroID())
- return true;
if (!returnStmt->getRetValue())
return true;
@@ -240,8 +237,6 @@ void UnnecessaryParen::VisitSomeStmt(const Stmt * stmt, const Expr* cond, String
{
if (ignoreLocation(stmt))
return;
- if (stmt->getLocStart().isMacroID())
- return;
auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(cond));
if (parenExpr) {
@@ -269,8 +264,6 @@ bool UnnecessaryParen::VisitCallExpr(const CallExpr* callExpr)
{
if (ignoreLocation(callExpr))
return true;
- if (callExpr->getLocStart().isMacroID())
- return true;
if (callExpr->getNumArgs() != 1 || isa<CXXOperatorCallExpr>(callExpr))
return true;
@@ -294,8 +287,6 @@ bool UnnecessaryParen::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr* callE
{
if (ignoreLocation(callExpr))
return true;
- if (callExpr->getLocStart().isMacroID())
- return true;
if (callExpr->getNumArgs() != 2)
return true;
@@ -334,8 +325,6 @@ bool UnnecessaryParen::VisitVarDecl(const VarDecl* varDecl)
{
if (ignoreLocation(varDecl))
return true;
- if (varDecl->getLocStart().isMacroID())
- return true;
if (!varDecl->getInit())
return true;