[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Refactor / Extract / ExtractExprIntoFunction.cpp
blob0fccc9298597ea403540bc87e39a63f53e5840ed
1 // RUN: clang-refactor extract -selection=test:%s %s -- -std=c++14 2>&1 | grep -v CHECK | FileCheck %s
4 void simpleExtractNoCaptures() {
5 int i = /*range=->+0:33*/1 + 2;
8 // CHECK: 1 '' results:
9 // CHECK: static int extracted() {
10 // CHECK-NEXT: return 1 + 2;{{$}}
11 // CHECK-NEXT: }{{[[:space:]].*}}
12 // CHECK-NEXT: void simpleExtractNoCaptures() {
13 // CHECK-NEXT: int i = /*range=->+0:33*/extracted();{{$}}
14 // CHECK-NEXT: }
16 void simpleExtractStmtNoCaptures() {
17 /*range astatement=->+1:13*/int a = 1;
18 int b = 2;
20 // CHECK: 1 'astatement' results:
21 // CHECK: static void extracted() {
22 // CHECK-NEXT: int a = 1;
23 // CHECK-NEXT: int b = 2;{{$}}
24 // CHECK-NEXT: }{{[[:space:]].*}}
25 // CHECK-NEXT: void simpleExtractStmtNoCaptures() {
26 // CHECK-NEXT: /*range astatement=->+1:13*/extracted();{{$}}
27 // CHECK-NEXT: }
30 void blankRangeNoExtraction() {
31 int i = /*range blank=*/1 + 2;
34 // CHECK: 1 'blank' results:
35 // CHECK-NEXT: the provided selection does not overlap with the AST nodes of interest
37 int outOfBodyCodeNoExtraction = /*range out_of_body_expr=->+0:72*/1 + 2;
39 struct OutOfBodyStuff {
40 int FieldInit = /*range out_of_body_expr=->+0:58*/1 + 2;
42 void foo(int x =/*range out_of_body_expr=->+0:58*/1 + 2);
45 auto inFunctionOutOfBody() -> decltype(/*range out_of_body_expr=->+0:79*/1 + 2) {
46 struct OutOfBodyStuff {
47 int FieldInit = /*range out_of_body_expr=->+0:60*/1 + 2;
49 void foo(int x =/*range out_of_body_expr=->+0:60*/1 + 2);
51 enum E {
52 X = /*range out_of_body_expr=->+0:48*/1 + 2
54 int x = 0;
55 using T = decltype(/*range out_of_body_expr=->+0:61*/x + 3);
56 return x;
59 // CHECK: 8 'out_of_body_expr' results:
60 // CHECK: the selected code is not a part of a function's / method's body
62 void simpleExpressionNoExtraction() {
63 int i = /*range simple_expr=->+0:41*/1 + /*range simple_expr=->+0:76*/(2);
64 (void) /*range simple_expr=->+0:40*/i;
65 (void)/*range simple_expr=->+0:47*/"literal";
66 (void)/*range simple_expr=->+0:41*/'c';
69 // CHECK: 5 'simple_expr' results:
70 // CHECK-NEXT: the selected expression is too simple to extract