| 1 |
301 |
jeremybenn |
// Test lambda mangling
|
| 2 |
|
|
// { dg-require-weak "" }
|
| 3 |
|
|
// { dg-options "-std=c++0x -fno-inline" }
|
| 4 |
|
|
|
| 5 |
|
|
template int algo(F fn) { return fn(); }
|
| 6 |
|
|
inline void g(int n) {
|
| 7 |
|
|
int bef(int i = []{ return 1; }());
|
| 8 |
|
|
// Default arguments of block-extern function declarations
|
| 9 |
|
|
// remain in the context of the encloding function body.
|
| 10 |
|
|
// The closure type is encoded as Z1giEUlvE_.
|
| 11 |
|
|
// The call operator of that type is _ZZ1giENKUlvE_clEv.
|
| 12 |
|
|
|
| 13 |
|
|
// { dg-final { scan-assembler "_ZZ1giENKUlvE_clEv" } }
|
| 14 |
|
|
// { dg-final { scan-assembler "weak\[^\n\r\]*_?_ZZ1giENKUlvE_clEv" { target { ! { *-*-darwin* *-*-mingw* *-*-cygwin } } } } }
|
| 15 |
|
|
|
| 16 |
|
|
algo([=]{return n+bef();});
|
| 17 |
|
|
// The captured entities do not participate in
|
| 18 |
|
|
// and so this closure type has the same as
|
| 19 |
|
|
// the previous one. It encoding is therefore Z1giEUlvE0_
|
| 20 |
|
|
// and the call operator is _ZZ1giENKUlvE0_clEv. The
|
| 21 |
|
|
// instance of "algo" being called is then
|
| 22 |
|
|
// _Z4algoIZ1giEUlvE0_EiT_.
|
| 23 |
|
|
|
| 24 |
|
|
// { dg-final { scan-assembler "_Z4algoIZ1giEUlvE0_EiT_" } }
|
| 25 |
|
|
// { dg-final { scan-assembler "_ZZ1giENKUlvE0_clEv" } }
|
| 26 |
|
|
|
| 27 |
|
|
int i = []{return 1;}();
|
| 28 |
|
|
|
| 29 |
|
|
}
|
| 30 |
|
|
|
| 31 |
|
|
struct S {
|
| 32 |
|
|
void f(int =
|
| 33 |
|
|
// Type: ZN1S1fEiiEd0_UlvE_
|
| 34 |
|
|
// Operator: _ZZN1S1fEiiEd0_NKUlvE_clEv
|
| 35 |
|
|
// { dg-final { scan-assembler "_ZZN1S1fEiiEd0_NKUlvE_clEv" } }
|
| 36 |
|
|
// { dg-final { scan-assembler "weak\[^\n\r\]*_?_ZZN1S1fEiiEd0_NKUlvE_clEv" { target { ! { *-*-darwin* *-*-mingw* *-*-cygwin } } } } }
|
| 37 |
|
|
[]{return 1;}()
|
| 38 |
|
|
// Type: ZN1S1fEiiEd0_UlvE0_
|
| 39 |
|
|
// Operator: _ZZN1S1fEiiEd0_NKUlvE0_clEv
|
| 40 |
|
|
// { dg-final { scan-assembler "_ZZN1S1fEiiEd0_NKUlvE0_clEv" } }
|
| 41 |
|
|
+ []{return 2;}(),
|
| 42 |
|
|
int =
|
| 43 |
|
|
// Type: ZN1S1fEiiEd_UlvE_
|
| 44 |
|
|
// Operator: _ZZN1S1fEiiEd_NKUlvE_clEv
|
| 45 |
|
|
// { dg-final { scan-assembler "_ZZN1S1fEiiEd_NKUlvE_clEv" } }
|
| 46 |
|
|
[]{return 3;}());
|
| 47 |
|
|
};
|
| 48 |
|
|
|
| 49 |
|
|
template struct R {
|
| 50 |
|
|
static int x;
|
| 51 |
|
|
};
|
| 52 |
|
|
template int R::x = []{return 1;}();
|
| 53 |
|
|
template int R::x;
|
| 54 |
|
|
// Type of lambda in intializer of R::x: N1RIiE1xMUlvE_E
|
| 55 |
|
|
// Corresponding operator(): _ZNK1RIiE1xMUlvE_clEv
|
| 56 |
|
|
// { dg-final { scan-assembler "_ZNK1RIiE1xMUlvE_clEv" } }
|
| 57 |
|
|
// { dg-final { scan-assembler "weak\[^\n\r\]*_?_ZNK1RIiE1xMUlvE_clEv" { target { ! { *-*-mingw* *-*-cygwin } } } } }
|
| 58 |
|
|
|
| 59 |
|
|
void bar()
|
| 60 |
|
|
{
|
| 61 |
|
|
// lambdas in non-vague linkage functions have internal linkage.
|
| 62 |
|
|
// { dg-final { scan-assembler-not "weak\[^\n\r\]*bar\[^\n\r\]*Ul" } }
|
| 63 |
|
|
[]{}();
|
| 64 |
|
|
}
|
| 65 |
|
|
|
| 66 |
|
|
// lambdas used in non-template, non-class body initializers are internal.
|
| 67 |
|
|
// { dg-final { scan-assembler-not "weak\[^\n\r\]*_ZNKUlv" } }
|
| 68 |
|
|
// { dg-final { scan-assembler-not "weak\[^\n\r\]*variable" } }
|
| 69 |
|
|
int variable = []{return 1;}();
|
| 70 |
|
|
|
| 71 |
|
|
// And a template instantiated with such a lambda is also internal.
|
| 72 |
|
|
// { dg-final { scan-assembler-not "weak\[^\n\r\]*algoIUl" } }
|
| 73 |
|
|
int var2 = algo([]{return 1;});
|
| 74 |
|
|
|
| 75 |
|
|
// As are lambdas used in non-class-body default arguments.
|
| 76 |
|
|
// { dg-final { scan-assembler-not "weak\[^\n\r\]*function" } }
|
| 77 |
|
|
void function (int i = []{return 1;}()+[]{return 1;}());
|
| 78 |
|
|
|
| 79 |
|
|
struct Foo
|
| 80 |
|
|
{
|
| 81 |
|
|
static int Int;
|
| 82 |
|
|
void Bar(int);
|
| 83 |
|
|
};
|
| 84 |
|
|
|
| 85 |
|
|
int Foo::Int = []{return 1;}();
|
| 86 |
|
|
// Even default arguments for member functions that appear outside the
|
| 87 |
|
|
// class body are internal.
|
| 88 |
|
|
// { dg-final { scan-assembler-not "weak\[^\n\r\]*Foo" } }
|
| 89 |
|
|
void Foo::Bar(int i = []{return 1;}()) {}
|
| 90 |
|
|
|
| 91 |
|
|
// Even default arguments for function templates.
|
| 92 |
|
|
// { dg-final { scan-assembler-not "weak\[^\n\r\]*fn2\[^\n\r\]*Ulv" } }
|
| 93 |
|
|
template
|
| 94 |
|
|
void fn2 (T t = []{return 1;}()) {}
|
| 95 |
|
|
|
| 96 |
|
|
int main()
|
| 97 |
|
|
{
|
| 98 |
|
|
g(42);
|
| 99 |
|
|
S().f();
|
| 100 |
|
|
function();
|
| 101 |
|
|
Foo().Bar();
|
| 102 |
|
|
fn2();
|
| 103 |
|
|
}
|