@@ -720,18 +720,24 @@ bool SimplifyBooleanExprCheck::issueDiag(const ASTContext &Context,
720720void SimplifyBooleanExprCheck::replaceWithThenStatement (
721721 const ASTContext &Context, const IfStmt *IfStatement,
722722 const Expr *BoolLiteral) {
723+ std::string Replacement = getText (Context, *IfStatement->getThen ());
724+ if (const Stmt *Init = IfStatement->getInit ()) {
725+ Replacement = (Twine (" { " ) + getText (Context, *Init) + Replacement + " }" ).str ();
726+ }
723727 issueDiag (Context, BoolLiteral->getBeginLoc (), SimplifyConditionDiagnostic,
724- IfStatement->getSourceRange (),
725- getText (Context, *IfStatement->getThen ()));
728+ IfStatement->getSourceRange (), Replacement);
726729}
727730
728731void SimplifyBooleanExprCheck::replaceWithElseStatement (
729732 const ASTContext &Context, const IfStmt *IfStatement,
730733 const Expr *BoolLiteral) {
731734 const Stmt *ElseStatement = IfStatement->getElse ();
735+ std::string Replacement = ElseStatement ? getText (Context, *ElseStatement) : " " ;
736+ if (const Stmt *Init = IfStatement->getInit ()) {
737+ Replacement = (Twine (" { " ) + getText (Context, *Init) + Replacement + " }" ).str ();
738+ }
732739 issueDiag (Context, BoolLiteral->getBeginLoc (), SimplifyConditionDiagnostic,
733- IfStatement->getSourceRange (),
734- ElseStatement ? getText (Context, *ElseStatement) : " " );
740+ IfStatement->getSourceRange (), Replacement);
735741}
736742
737743void SimplifyBooleanExprCheck::replaceWithCondition (
0 commit comments