1 // Test lambda mangling
2 // { dg-require-weak "" }
3 // { dg-do compile { target c++11 } }
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 template<typename T> int R<T>::x = []{return 1;}();
54 template int R<int>::x;
55 // Type of lambda in intializer of R<int>::x: N1RIiE1xMUlvE_E
56 // Corresponding operator(): _ZNK1RIiE1xMUlvE_clEv
57 // { dg-final { scan-assembler "_ZNK1RIiE1xMUlvE_clEv" } }
58 // { dg-final { scan-assembler "weak\[^\n\r\]*_?_ZNK1RIiE1xMUlvE_clEv" { target { ! { *-*-mingw* *-*-cygwin } } } } }
62 // lambdas in non-vague linkage functions have internal linkage.
63 // { dg-final { scan-assembler-not "weak\[^\n\r\]*bar\[^\n\r\]*Ul" } }
67 // lambdas used in non-template, non-class body initializers are internal.
68 // { dg-final { scan-assembler-not "weak\[^\n\r\]*_ZNKUlv" } }
69 // { dg-final { scan-assembler-not "weak\[^\n\r\]*variable" } }
70 int variable = []{return 1;}();
72 // And a template instantiated with such a lambda is also internal.
73 // { dg-final { scan-assembler-not "weak\[^\n\r\]*algoIUl" } }
74 int var2 = algo([]{return 1;});
76 // As are lambdas used in non-class-body default arguments.
77 // { dg-final { scan-assembler-not "weak\[^\n\r\]*function" } }
78 void function (int i = []{return 1;}()+[]{return 1;}());
86 int Foo::Int = []{return 1;}();
87 // Even default arguments for member functions that appear outside the
88 // class body are internal.
89 // { dg-final { scan-assembler-not "weak\[^\n\r\]*Foo" } }
90 void Foo::Bar(int i = []{return 1;}()) {}
92 // Even default arguments for function templates.
93 // { dg-final { scan-assembler-not "weak\[^\n\r\]*fn2\[^\n\r\]*Ulv" } }
95 void fn2 (T t = []{return 1;}()) {}