• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 template <class T>
2 struct function {
3 };
4 
5 
test()6 void test() {
7   void (*x)(int, double) = nullptr;
8 
9   function<void(int, double)> y = {};
10   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:7:28 %s -o - | FileCheck -check-prefix=CHECK-1 %s
11   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:9:35 %s -o - | FileCheck -check-prefix=CHECK-1 %s
12   // CHECK-1: COMPLETION: Pattern : [<#=#>](int <#parameter#>, double <#parameter#>) { <#body#> }
13 
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:15:36 %s -o - | FileCheck -check-prefix=CHECK-2 %s
17   // CHECK-2: COMPLETION: Pattern : [<#=#>](void (* <#parameter#>)(int)) { <#body#> }
18 
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:20:24 %s -o - | FileCheck -check-prefix=CHECK-3 %s
22   // CHECK-3: COMPLETION: Pattern : [<#=#>] { <#body#> }
23 }
24 
25 template <class T, class Allocator = int>
26 struct vector {};
27 
test2()28 void test2() {
29   // == Try to preserve types as written.
30   function<void(vector<int>)> a = {};
31 
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:30:35 %s -o - | FileCheck -check-prefix=CHECK-4 %s
35   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:33:24 %s -o - | FileCheck -check-prefix=CHECK-4 %s
36   // CHECK-4: COMPLETION: Pattern : [<#=#>](vector<int> <#parameter#>) { <#body#> }
37 }
38 
39 // Check another common function wrapper name.
40 template <class T> struct unique_function {};
41 
test3()42 void test3() {
43   unique_function<void()> a = {};
44   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:43:31 %s -o - | FileCheck -check-prefix=CHECK-5 %s
45   // CHECK-5: COMPLETION: Pattern : [<#=#>] { <#body#> }
46 }
47 
48 template <class T, class U> struct weird_function {};
test4()49 void test4() {
50   weird_function<void(), int> b = {};
51   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:50:35 %s -o - | FileCheck -check-prefix=CHECK-6 %s
52   // CHECK-6-NOT: COMPLETION: Pattern : [<#=
53 }
54 
test5()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:57:24 %s -o - | FileCheck -check-prefix=CHECK-7 %s
59   // CHECK-7: COMPLETION: Pattern : [<#=
60   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:57:24 %s -o - | FileCheck -check-prefix=CHECK-8 %s
61   // CHECK-8-NOT: COMPLETION: Pattern : [<#=
62 }
63 
test6()64 void test6() {
65   auto my_lambda = [&](int a, double &b) { return 1.f; };
66   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:65:58 %s -o - | FileCheck -check-prefix=CHECK-9 %s
67   // CHECK-9: [#float#]my_lambda(<#int a#>, <#double &b#>)[# const#]
68 }
69 
test7()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:71:70 %s -o - | FileCheck -check-prefix=CHECK-10 %s
73   // CHECK-10: [#auto#]generic_lambda(<#auto a#>, <#const auto &b#>)[# const#]
74 }
75