summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-05-18 14:21:58 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-05-18 14:21:58 +0200
commit64e5915b7a2c07c740aae25a4a6d00a306e704e4 (patch)
tree09b4148191301190c636f16ca290323579c81138 /compilerplugins
parent8584b7f57c87b111526d5cc75cc1c45646ebf278 (diff)
Avoid nested automatic rewrites
...which would come out garbled. One place is > bool bRet = SfxItemState::SET == pSet->GetItemState( i, rAttr.Which() != RES_TXTATR_AUTOFMT, &pItem ); in SwAttrHandler::PushAndChg (sw/source/core/text/atrstck.cxx) Change-Id: I1486313b25850dc59e10edb38b8bd28a30e6aa63
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/comparisonwithconstant.cxx29
1 files changed, 28 insertions, 1 deletions
diff --git a/compilerplugins/clang/comparisonwithconstant.cxx b/compilerplugins/clang/comparisonwithconstant.cxx
index d200d8ec212d..b55a73e05c17 100644
--- a/compilerplugins/clang/comparisonwithconstant.cxx
+++ b/compilerplugins/clang/comparisonwithconstant.cxx
@@ -33,11 +33,37 @@ public:
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
+ // Deliberatley drop RecursiveASTVisitor::TraverseBinEQ's DataRecursionQueue
+ // parameter; TraveseBinEQ must use stack instead of data recursion for any
+ // children's VisitBinaryOperator to see changes to occurrence_ by a parent
+ // VisitBinaryOperator:
+ bool TraverseBinEQ(BinaryOperator * S)
+ {
+ auto const saved = occurrence_;
+ auto const ret = RecursiveASTVisitor::TraverseBinEQ(S);
+ occurrence_ = saved;
+ return ret;
+ }
+
+ // Deliberatley drop RecursiveASTVisitor::TraverseBinNE's DataRecursionQueue
+ // parameter; TraveseBinNE must use stack instead of data recursion for any
+ // children's VisitBinaryOperator to see changes to occurrence_ by a parent
+ // VisitBinaryOperator:
+ bool TraverseBinNE(BinaryOperator * S)
+ {
+ auto const saved = occurrence_;
+ auto const ret = RecursiveASTVisitor::TraverseBinNE(S);
+ occurrence_ = saved;
+ return ret;
+ }
+
bool VisitBinaryOperator(const BinaryOperator *);
private:
bool rewrite(const BinaryOperator *);
std::string getExprAsString(SourceRange range);
SourceRange ignoreMacroExpansions(SourceRange range);
+
+ bool occurrence_ = false;
};
bool ComparisonWithConstant::VisitBinaryOperator(const BinaryOperator* binaryOp)
@@ -63,13 +89,14 @@ bool ComparisonWithConstant::VisitBinaryOperator(const BinaryOperator* binaryOp)
if (binaryOp->getRHS()->isEvaluatable(compiler.getASTContext())) {
return true;
}
- if (!rewrite(binaryOp))
+ if (occurrence_ || !rewrite(binaryOp))
{
report(
DiagnosticsEngine::Warning, "Rather put constant on right when comparing",
binaryOp->getSourceRange().getBegin())
<< binaryOp->getSourceRange();
}
+ occurrence_ = true;
return true;
}