1 // Test lambda mangling
2 // { dg-options "-std=c++0x -fno-inline" }
4 template<typename F> int algo(F fn) { return fn(); }
6 int bef(int i = []{ return 1; }());
7 // Default arguments of block-extern function declarations
8 // remain in the context of the encloding function body.
9 // The closure type is encoded as Z1giEUlvE_.
10 // The call operator of that type is _ZZ1giENKUlvE_clEv.
12 // { dg-final { scan-assembler "_ZZ1giENKUlvE_clEv" } }
13 // { dg-final { scan-assembler "weak\[ \t\]*_?_ZZ1giENKUlvE_clEv" { target { ! { *-*-darwin* *-*-mingw* *-*-cygwin } } } } }
15 algo([=]{return n+bef();});
16 // The captured entities do not participate in <lambda-sig>
17 // and so this closure type has the same <lambda-sig> as
18 // the previous one. It encoding is therefore Z1giEUlvE0_
19 // and the call operator is _ZZ1giENKUlvE0_clEv. The
20 // instance of "algo" being called is then
21 // _Z4algoIZ1giEUlvE0_EiT_.
23 // { dg-final { scan-assembler "_Z4algoIZ1giEUlvE0_EiT_" } }
24 // { dg-final { scan-assembler "_ZZ1giENKUlvE0_clEv" } }
26 int i = []{return 1;}();
32 // Type: ZN1S1fEiiEd0_UlvE_
33 // Operator: _ZZN1S1fEiiEd0_NKUlvE_clEv
34 // { dg-final { scan-assembler "_ZZN1S1fEiiEd0_NKUlvE_clEv" } }
35 // { dg-final { scan-assembler "weak\[ \t\]*_?_ZZN1S1fEiiEd0_NKUlvE_clEv" { target { ! { *-*-darwin* *-*-mingw* *-*-cygwin } } } } }
37 // Type: ZN1S1fEiiEd0_UlvE0_
38 // Operator: _ZZN1S1fEiiEd0_NKUlvE0_clEv
39 // { dg-final { scan-assembler "_ZZN1S1fEiiEd0_NKUlvE0_clEv" } }
42 // Type: ZN1S1fEiiEd_UlvE_
43 // Operator: _ZZN1S1fEiiEd_NKUlvE_clEv
44 // { dg-final { scan-assembler "_ZZN1S1fEiiEd_NKUlvE_clEv" } }
48 template<typename T> struct R {
51 template<typename T> int R<T>::x = []{return 1;}();
52 template int R<int>::x;
53 // Type of lambda in intializer of R<int>::x: N1RIiE1xMUlvE_E
54 // Corresponding operator(): _ZNK1RIiE1xMUlvE_clEv
55 // { dg-final { scan-assembler "_ZNK1RIiE1xMUlvE_clEv" } }
56 // { dg-final { scan-assembler "weak\[ \t\]*_?_ZNK1RIiE1xMUlvE_clEv" { target { ! { *-*-mingw* *-*-cygwin } } } } }
60 // lambdas in non-vague linkage functions have internal linkage.
61 // { dg-final { scan-assembler-not "weak\[^\n\r\]*bar\[^\n\r\]*Ul" } }
65 // lambdas used in non-template, non-class body initializers are internal.
66 // { dg-final { scan-assembler-not "weak\[^\n\r\]*_ZNKUlv" } }
67 // { dg-final { scan-assembler-not "weak\[^\n\r\]*variable" } }
68 int variable = []{return 1;}();
70 // And a template instantiated with such a lambda is also internal.
71 // { dg-final { scan-assembler-not "weak\[^\n\r\]*algoIUl" } }
72 int var2 = algo([]{return 1;});
74 // As are lambdas used in non-class-body default arguments.
75 // { dg-final { scan-assembler-not "weak\[^\n\r\]*function" } }
76 void function (int i = []{return 1;}()+[]{return 1;}());
84 int Foo::Int = []{return 1;}();
85 // Even default arguments for member functions that appear outside the
86 // class body are internal.
87 // { dg-final { scan-assembler-not "weak\[^\n\r\]*Foo" } }
88 void Foo::Bar(int i = []{return 1;}()) {}
90 // Even default arguments for function templates.
91 // { dg-final { scan-assembler-not "weak\[^\n\r\]*fn2\[^\n\r\]*Ulv" } }
93 void fn2 (T t = []{return 1;}()) {}