From d7f2a35cac9bded28180dab6394b052983d23dab Mon Sep 17 00:00:00 2001 From: Kirill Bobyrev Date: Fri, 16 Sep 2016 10:12:08 +0000 Subject: [PATCH] [clang-tidy] Bugfix for readability-redundant-control-flow check This check did not create FixItHints when the statement before the redundant control flow was not followed by a semicolon. Patch by Malcolm Parsons! Reviewers: alexfh Differential Revision: https://reviews.llvm.org/D24500 llvm-svn: 281713 --- .../clang-tidy/readability/RedundantControlFlowCheck.cpp | 2 +- .../test/clang-tidy/readability-redundant-control-flow.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp index 54a26e24abbc..22f1111025c8 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp @@ -83,7 +83,7 @@ void RedundantControlFlowCheck::issueDiagnostic( dyn_cast(*Previous)->getLocEnd(), tok::semi, SM, Result.Context->getLangOpts(), /*SkipTrailingWhitespaceAndNewLine=*/true); - else + if (!Start.isValid()) Start = StmtRange.getBegin(); auto RemovedRange = CharSourceRange::getCharRange( Start, diff --git a/clang-tools-extra/test/clang-tidy/readability-redundant-control-flow.cpp b/clang-tools-extra/test/clang-tidy/readability-redundant-control-flow.cpp index 09dec6f6b8e3..0352e3a94446 100644 --- a/clang-tools-extra/test/clang-tidy/readability-redundant-control-flow.cpp +++ b/clang-tools-extra/test/clang-tidy/readability-redundant-control-flow.cpp @@ -179,6 +179,7 @@ void template_return(T check) { // CHECK-FIXES: {{^}} if (check < T(0)) {{{$}} // CHECK-FIXES-NEXT: {{^ return;$}} // CHECK-FIXES-NEXT: {{^ *}$}} +// CHECK-FIXES-NEXT: {{^ *}$}} template <> void template_return(int check) { @@ -191,6 +192,7 @@ void template_return(int check) { // CHECK-FIXES: {{^}} if (check < 0) {{{$}} // CHECK-FIXES-NEXT: {{^ return;$}} // CHECK-FIXES-NEXT: {{^ *}$}} +// CHECK-FIXES-NEXT: {{^ *}$}} template void template_loop(T end) {