From: Shaurya Gupta Date: Thu, 8 Aug 2019 08:37:49 +0000 (+0000) Subject: [Extract] Fixed SemicolonExtractionPolicy for SwitchStmt and SwitchCase X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f4d08425a85cf030a86f4895c3cf5d39b91a4fd0;p=clang [Extract] Fixed SemicolonExtractionPolicy for SwitchStmt and SwitchCase Reviewers: arphaman, sammccall Subscribers: dexonsmith, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65883 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368267 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp b/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp index 533c373e35..9b0c37b170 100644 --- a/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp +++ b/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp @@ -40,8 +40,11 @@ bool isSemicolonRequiredAfter(const Stmt *S) { return isSemicolonRequiredAfter(CXXFor->getBody()); if (const auto *ObjCFor = dyn_cast(S)) return isSemicolonRequiredAfter(ObjCFor->getBody()); + if(const auto *Switch = dyn_cast(S)) + return isSemicolonRequiredAfter(Switch->getBody()); + if(const auto *Case = dyn_cast(S)) + return isSemicolonRequiredAfter(Case->getSubStmt()); switch (S->getStmtClass()) { - case Stmt::SwitchStmtClass: case Stmt::CXXTryStmtClass: case Stmt::ObjCAtSynchronizedStmtClass: case Stmt::ObjCAutoreleasePoolStmtClass: diff --git a/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp b/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp index 5caf9d4526..97f1247576 100644 --- a/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp +++ b/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp @@ -64,6 +64,7 @@ void extractStatementNotSemiSwitch() { // CHECK-NEXT: extracted();{{$}} // CHECK-NEXT: } + void extractStatementNotSemiWhile() { /*range eextract=->+2:4*/while (true) { int x = 0; @@ -190,3 +191,15 @@ void careForNonCompoundSemicolons2() { // CHECK-NEXT: extracted();{{$}} // CHECK-NEXT: // // CHECK-NEXT: } + +void careForSwitchSemicolon() { + /*range mextract=->+0:51*/switch(0) default: break; +} +// CHECK: 1 'mextract' results: +// CHECK: static void extracted() { +// CHECK-NEXT: switch(0) default: break;{{$}} +// CHECK-NEXT: }{{[[:space:]].*}} +// CHECK-NEXT: void careForSwitchSemicolon() { +// CHECK-NEXT: extracted();{{$}} +// CHECK-NEXT: } +