1 struct Base {
2   int t;
3 };
4 struct Foo : public Base {
5   int x;
6   Base b;
7   void foo();
8 };
9 
foo()10 void foo() {
11   Foo F{.x = 2, .b.t = 0};
12   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:11:10 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-CC1 %s
13   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:11:18 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-CC1 %s
14   // CHECK-CC1: COMPLETION: b : [#Base#]b
15   // CHECK-CC1-NEXT: COMPLETION: x : [#int#]x
16   // CHECK-CC1-NOT: foo
17   // CHECK-CC1-NOT: t
18 
19   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:11:20 %s -o - | FileCheck -check-prefix=CHECK-NESTED %s
20   // CHECK-NESTED: COMPLETION: t : [#int#]t
21 
22   Base B = {.t = 2};
23   auto z = [](Base B) {};
24   z({.t = 1});
25   z(Base{.t = 2});
26   z((Base){.t = 2});
27   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:22:14 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-CC2 %s
28   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:24:7 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-CC2 %s
29   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:25:11 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-CC2 %s
30   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:26:13 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-CC2 %s
31   // CHECK-CC2: COMPLETION: t : [#int#]t
32 
33   Foo G1{.b = {.t = 0}};
34   Foo G2{.b{.t = 0}};
35   Foo G3{b: {.t = 0}};
36   // RUN: %clang_cc1 -code-completion-at=%s:33:17 -fsyntax-only -code-completion-patterns %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-NESTED-2 %s
37   // RUN: %clang_cc1 -code-completion-at=%s:34:14 -fsyntax-only -code-completion-patterns %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-NESTED-2 %s
38   // RUN: %clang_cc1 -code-completion-at=%s:35:15 -fsyntax-only -code-completion-patterns %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-NESTED-2 %s
39   // CHECK-NESTED-2: COMPLETION: t : [#int#]t
40 }
41 
42 // Handle templates
43 template <typename T>
44 struct Test { T x; };
45 template <>
46 struct Test<int> {
47   int x;
48   char y;
49 };
bar()50 void bar() {
51   Test<char> T{.x = 2};
52   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:51:17 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-CC3 %s
53   // CHECK-CC3: COMPLETION: x : [#T#]x
54   Test<int> X{.x = 2};
55   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:54:16 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-CC4 %s
56   // CHECK-CC4: COMPLETION: x : [#int#]x
57   // CHECK-CC4-NEXT: COMPLETION: y : [#char#]y
58 }
59 
60 template <typename T>
aux()61 void aux() {
62   Test<T> X{.x = T(2)};
63   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:62:14 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-CC3 %s
64 }
65 
66 namespace signature_regression {
67   // Verify that an old bug is gone: passing an init-list as a constructor arg
68   // would emit overloads as a side-effect.
69   struct S{int x;};
70   int wrongFunction(S);
71   int rightFunction();
72   int dummy = wrongFunction({1});
73   int x = rightFunction();
74   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:73:25 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-SIGNATURE-REGRESSION %s
75   // CHECK-SIGNATURE-REGRESSION-NOT: OVERLOAD: [#int#]wrongFunction
76   // CHECK-SIGNATURE-REGRESSION:     OVERLOAD: [#int#]rightFunction
77   // CHECK-SIGNATURE-REGRESSION-NOT: OVERLOAD: [#int#]wrongFunction
78 }
79 
80 struct WithAnon {
81   int outer;
82   struct { int inner; };
83 };
84 auto TestWithAnon = WithAnon { .inner = 2 };
85   // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:84:33 %s -o - -std=c++2a | FileCheck -check-prefix=CHECK-CC5 %s
86   // CHECK-CC5: COMPLETION: inner : [#int#]inner
87   // CHECK-CC5: COMPLETION: outer : [#int#]outer
88