Index: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp @@ -75,6 +75,9 @@ if (hasPtrOrReferenceInFunc(Func, CondVar)) return; + if (isChangedBefore(OuterIf->getCond(), InnerIf, CondVar, Result.Context)) + return; + if (isChangedBefore(OuterIf->getThen(), InnerIf, CondVar, Result.Context)) return; @@ -123,7 +126,7 @@ CharSourceRange::getTokenRange(IfBegin, IfEnd)); } - // For comound statements also remove the right brace at the end. + // For compound statements also remove the right brace at the end. if (isa(Body)) Diag << FixItHint::CreateRemoval( CharSourceRange::getTokenRange(Body->getEndLoc(), Body->getEndLoc())); Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp +++ clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp @@ -6,7 +6,8 @@ bool isBurning(); bool isReallyBurning(); bool isCollapsing(); -void tryToExtinguish(bool&); +bool tryToExtinguish(bool&); +bool tryToExtinguishByVal(bool &); void tryPutFireOut(); bool callTheFD(); void scream(); @@ -948,6 +949,24 @@ } } +void negative_by_ref(bool isSet) { + if (tryToExtinguish(isSet) && isSet) { + if (tryToExtinguish(isSet) && isSet) { + // NO-MESSAGE: fire may have been extinguished + scream(); + } + } +} + +void negative_by_val(bool isSet) { + if (tryToExtinguishByVal(isSet) && isSet) { + if (tryToExtinguishByVal(isSet) && isSet) { + // NO-MESSAGE: fire may have been extinguished + scream(); + } + } +} + void negative_reassigned() { bool onFire = isBurning(); if (onFire) { @@ -1077,9 +1096,9 @@ int positive_expr_with_cleanups() { class RetT { public: - RetT(const int _code) : code_(_code) {} - bool Ok() const { return code_ == 0; } - static RetT Test(bool &_isSet) { return 0; } + RetT(const int code); + bool Ok() const; + static RetT Test(bool isSet); private: int code_;