1 // Test lambda mangling
2 // { dg-do compile { target c++11 } }
3 // { dg-require-weak "" }
4 // { dg-options "-fno-inline" }
6 template<typename F> int algo(F fn) { return fn(); }
8 int bef(int i = []{ return 1; }());
9 // Default arguments of block-extern function declarations
10 // remain in the context of the encloding function body.
11 // The closure type is encoded as Z1giEUlvE_.
12 // The call operator of that type is _ZZ1giENKUlvE_clEv.
14 // { dg-final { scan-assembler "_ZZ1giENKUlvE_clEv" } }
15 // { dg-final { scan-assembler "weak\[^\n\r\]*_?_ZZ1giENKUlvE_clEv" { target { ! { *-*-darwin* *-*-mingw* *-*-cygwin } } } } }
17 algo([=]{return n+bef();});
18 // The captured entities do not participate in <lambda-sig>
19 // and so this closure type has the same <lambda-sig> as
20 // the previous one. It encoding is therefore Z1giEUlvE0_
21 // and the call operator is _ZZ1giENKUlvE0_clEv. The
22 // instance of "algo" being called is then
23 // _Z4algoIZ1giEUlvE0_EiT_.
25 // { dg-final { scan-assembler "_Z4algoIZ1giEUlvE0_EiT_" } }
26 // { dg-final { scan-assembler "_ZZ1giENKUlvE0_clEv" } }
28 int i = []{return 1;}();
34 // Type: ZN1S1fEiiEd0_UlvE_
35 // Operator: _ZZN1S1fEiiEd0_NKUlvE_clEv
36 // { dg-final { scan-assembler "_ZZN1S1fEiiEd0_NKUlvE_clEv" } }
37 // { dg-final { scan-assembler "weak\[^\n\r\]*_?_ZZN1S1fEiiEd0_NKUlvE_clEv" { target { ! { *-*-darwin* *-*-mingw* *-*-cygwin } } } } }
39 // Type: ZN1S1fEiiEd0_UlvE0_
40 // Operator: _ZZN1S1fEiiEd0_NKUlvE0_clEv
41 // { dg-final { scan-assembler "_ZZN1S1fEiiEd0_NKUlvE0_clEv" } }
44 // Type: ZN1S1fEiiEd_UlvE_
45 // Operator: _ZZN1S1fEiiEd_NKUlvE_clEv
46 // { dg-final { scan-assembler "_ZZN1S1fEiiEd_NKUlvE_clEv" } }
50 template<typename T> struct R {
53 // "int i;" makes the op() non-constexpr in C++17.
54 template<typename T> int R<T>::x = []{int i; return 1;}();
55 template int R<int>::x;
56 // Type of lambda in intializer of R<int>::x: N1RIiE1xMUlvE_E
57 // Corresponding operator(): _ZNK1RIiE1xMUlvE_clEv
58 // { dg-final { scan-assembler "_ZNK1RIiE1xMUlvE_clEv" } }
59 // { dg-final { scan-assembler "weak\[^\n\r\]*_?_ZNK1RIiE1xMUlvE_clEv" { target { ! { *-*-mingw* *-*-cygwin } } } } }
63 // lambdas in non-vague linkage functions have internal linkage.
64 // { dg-final { scan-assembler-not "weak\[^\n\r\]*bar\[^\n\r\]*Ul" } }
68 // lambdas used in non-template, non-class body initializers are internal.
69 // { dg-final { scan-assembler-not "weak\[^\n\r\]*_ZNKUlv" } }
70 // { dg-final { scan-assembler-not "weak\[^\n\r\]*variable" } }
71 int variable = []{return 1;}();
73 // And a template instantiated with such a lambda is also internal.
74 // { dg-final { scan-assembler-not "weak\[^\n\r\]*algoIUl" } }
75 int var2 = algo([]{return 1;});
77 // As are lambdas used in non-class-body default arguments.
78 // { dg-final { scan-assembler-not "weak\[^\n\r\]*function" } }
79 void function (int i = []{return 1;}()+[]{return 1;}());
87 int Foo::Int = []{return 1;}();
88 // Even default arguments for member functions that appear outside the
89 // class body are internal.
90 // { dg-final { scan-assembler-not "weak\[^\n\r\]*Foo" } }
91 void Foo::Bar(int i = []{return 1;}()) {}
93 // Even default arguments for function templates.
94 // { dg-final { scan-assembler-not "weak\[^\n\r\]*fn2\[^\n\r\]*Ulv" } }
96 void fn2 (T t = []{return 1;}()) {}