[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeCompletion / lambdas.cpp
blob53524fc97c7b8a02c3be77a1c8978cb1da24952a
1 template <class T>
2 struct function {
3 };
6 void test() {
7 void (*x)(int, double) = nullptr;
9 function<void(int, double)> y = {};
10 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:%(line-3):28 %s -o - | FileCheck -check-prefix=CHECK-1 %s
11 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:%(line-2):35 %s -o - | FileCheck -check-prefix=CHECK-1 %s
12 // CHECK-1: COMPLETION: Pattern : [<#=#>](int <#parameter#>, double <#parameter#>) { <#body#> }
14 // == Placeholders for suffix types must be placed properly.
15 function<void(void(*)(int))> z = {};
16 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:%(line-1):36 %s -o - | FileCheck -check-prefix=CHECK-2 %s
17 // CHECK-2: COMPLETION: Pattern : [<#=#>](void (* <#parameter#>)(int)) { <#body#> }
19 // == No need for a parameter list if function has no parameters.
20 function<void()> a = {};
21 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:%(line-1):24 %s -o - | FileCheck -check-prefix=CHECK-3 %s
22 // CHECK-3: COMPLETION: Pattern : [<#=#>] { <#body#> }
25 template <class T, class Allocator = int>
26 struct vector {};
28 void test2() {
29 // == Try to preserve types as written.
30 function<void(vector<int>)> a = {};
32 using function_typedef = function<void(vector<int>)>;
33 function_typedef b = {};
34 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:%(line-4):35 %s -o - | FileCheck -check-prefix=CHECK-4 %s
35 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:%(line-2):24 %s -o - | FileCheck -check-prefix=CHECK-4 %s
36 // CHECK-4: COMPLETION: Pattern : [<#=#>](vector<int> <#parameter#>) { <#body#> }
39 // Check another common function wrapper name.
40 template <class T> struct unique_function {};
42 void test3() {
43 unique_function<void()> a = {};
44 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:%(line-1):31 %s -o - | FileCheck -check-prefix=CHECK-5 %s
45 // CHECK-5: COMPLETION: Pattern : [<#=#>] { <#body#> }
48 template <class T, class U> struct weird_function {};
49 void test4() {
50 weird_function<void(), int> b = {};
51 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:%(line-1):35 %s -o - | FileCheck -check-prefix=CHECK-6 %s
52 // CHECK-6-NOT: COMPLETION: Pattern : [<#=
55 void test5() {
56 // Completions are only added when -code-completion-patterns are enabled.
57 function<void()> b = {};
58 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:%(line-1):24 %s -o - | FileCheck -check-prefix=CHECK-7 %s
59 // CHECK-7: COMPLETION: Pattern : [<#=
60 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-3):24 %s -o - | FileCheck -check-prefix=CHECK-8 %s
61 // CHECK-8-NOT: COMPLETION: Pattern : [<#=
64 void test6() {
65 auto my_lambda = [&](int a, double &b) { return 1.f; };
66 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):58 %s -o - | FileCheck -check-prefix=CHECK-9 %s
67 // CHECK-9: [#float#]my_lambda(<#int a#>, <#double &b#>)[# const#]
70 void test7() {
71 auto generic_lambda = [&](auto a, const auto &b) { return a + b; };
72 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):70 %s -o - | FileCheck -check-prefix=CHECK-10 %s
73 // CHECK-10: [#auto#]generic_lambda(<#auto a#>, <#const auto &b#>)[# const#]