[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / merge-lambdas.cpp
blob113a1fbac638c932a787bb4e9abaf7a754f432ec
1 // RUN: %clang_cc1 -std=c++14 -fmodules -verify %s -emit-llvm-only
2 // expected-no-diagnostics
4 #pragma clang module build A
5 module A {}
6 #pragma clang module contents
7 #pragma clang module begin A
8 template<typename T> auto f() { return []{}; }
9 #pragma clang module end
10 #pragma clang module endbuild
12 #pragma clang module build B
13 module B {}
14 #pragma clang module contents
15 #pragma clang module begin B
16 #pragma clang module import A
17 inline auto x1() { return f<int>(); }
18 inline auto z() { return []{}; }
19 inline auto x2() { return z(); }
21 struct Function {
22 template<typename T>
23 Function(T t) : p(new T((T&&)t)) {}
25 void *p;
28 struct Outer {
29 struct Inner {
30 Inner() {}
31 Function f = []{};
33 Outer(Inner = Inner());
36 inline void use_nested_1() { Outer o; }
37 #pragma clang module end
38 #pragma clang module endbuild
40 #pragma clang module build C
41 module C {}
42 #pragma clang module contents
43 #pragma clang module begin C
44 #pragma clang module import A
45 inline auto y1() { return f<int>(); }
46 inline auto z() { return []{}; }
47 inline auto y2() { return z(); }
48 inline auto q() { return []{}; }
49 inline auto y3() { return q(); }
51 struct Function {
52 template<typename T>
53 Function(T t) : p(new T((T&&)t)) {}
55 void *p;
58 struct Outer {
59 struct Inner {
60 Inner() {}
61 Function f = []{};
63 Outer(Inner = Inner());
66 inline void use_nested_2() { Outer o; }
67 #pragma clang module end
68 #pragma clang module endbuild
70 inline auto q() { return []{}; }
71 inline auto x3() { return q(); }
73 #pragma clang module import B
74 #pragma clang module import C
75 using T = decltype(x1);
76 using T = decltype(y1);
78 using U = decltype(x2);
79 using U = decltype(y2);
81 using V = decltype(x3);
82 using V = decltype(y3);
84 #pragma clang module import A
85 void (*p)() = f<int>();
87 void use_nested() {
88 use_nested_1();
89 use_nested_2();