Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/lambda/lambda-type.C

raw
1 // Every id-expression that is a use (_basic.def.odr_ 3.2) of an entity
2 // captured by copy is transformed into an access to the corresponding
3 // unnamed data member of the closure type.
4 //...
5 // Every occurrence of decltype((x)) where x is a possibly parenthesized
6 // id-expression that names an entity of automatic storage duration is
7 // treated as if x were transformed into an access to a corresponding data
8 // member of the closure type that would have been declared if x were a use
9 // of the denoted entity.
10
11 // So, other appearances of 'x' within decltype do not refer to the closure
12 // member, because they are not "use"s in the sense of 3.2.
13
14 // { dg-do compile { target c++11 } }
15
16 template<class T, class U>
17 struct same_type;
18 template <class T>
19 struct same_type<T,T> { };
20
21 int main()
22 {
23 int i;
24 [=] {
25 same_type<decltype(i),int>();
26 same_type<decltype((i)),int const&>();
27 i+1;
28 same_type<decltype((i)),int const&>();
29 same_type<decltype(i),int>();
30 };
31 [=] {
32 same_type<decltype(i),int>();
33 same_type<decltype((i)),int const&>();
34 same_type<decltype(i),int>();
35 };
36 [=] () mutable {
37 same_type<decltype(i),int>();
38 same_type<decltype((i)),int &>();
39 same_type<decltype(i),int>();
40 };
41 [&] {
42 same_type<decltype(i),int>();
43 same_type<decltype((i)),int &>();
44 same_type<decltype(i),int>();
45 };
46 [i] {
47 same_type<decltype(i),int>();
48 same_type<decltype((i)),int const&>();
49 };
50 [&,i] {
51 same_type<decltype(i),int>();
52 same_type<decltype((i)),int const&>();
53 };
54 [i] () mutable {
55 same_type<decltype(i),int>();
56 same_type<decltype((i)),int &>();
57 };
58 [&,i] () mutable {
59 same_type<decltype(i),int>();
60 same_type<decltype((i)),int &>();
61 };
62 [&i] {
63 same_type<decltype(i),int>();
64 same_type<decltype((i)),int &>();
65 };
66 [=,&i] {
67 same_type<decltype(i),int>();
68 same_type<decltype((i)),int &>();
69 };
70 [] {
71 same_type<decltype(i),int>();
72 same_type<decltype((i)),int const&>(); // { dg-error "" "not captured" }
73 };
74 }