]>
Commit | Line | Data |
---|---|---|
38179091 | 1 | // Tests for late-specified return type. |
f57ca1ea JM |
2 | // { dg-options "-std=c++0x" } |
3 | ||
4 | auto f() -> int | |
5 | { | |
6 | return 0; | |
7 | } | |
8 | ||
9 | template<class T, class U> | |
18802917 JM |
10 | auto add(T t, U u) -> decltype (t+u) |
11 | { | |
12 | return t+u; | |
13 | } | |
b344d949 JM |
14 | |
15 | template<class T, class U> | |
38179091 JM |
16 | decltype(T()+U()) add2(T t, U u) |
17 | { | |
18 | return t+u; | |
19 | } | |
b344d949 JM |
20 | |
21 | template <class T, class U> | |
38179091 JM |
22 | U ag (T, U) |
23 | { | |
24 | return U(); | |
25 | } | |
b344d949 JM |
26 | |
27 | template<class T, class U> | |
38179091 JM |
28 | auto add3(T t, U u) -> decltype (ag(t,u)) |
29 | { | |
30 | return ag(t,u); | |
31 | } | |
32 | ||
a77f94e2 JM |
33 | template<class T, class U> |
34 | decltype(*(T*)0+*(U*)0) add4(T t, U u) | |
35 | { | |
36 | return t+u; | |
37 | } | |
38 | ||
38179091 JM |
39 | template <class T> |
40 | struct A | |
41 | { | |
42 | T f() {} | |
43 | template <class U> | |
44 | T g() {} | |
45 | template <class V> | |
46 | struct B | |
47 | { | |
48 | int MEM; | |
49 | }; | |
50 | }; | |
51 | ||
52 | template <class T> | |
53 | auto f(T* t) -> decltype (t->f()) | |
54 | { | |
55 | return t->f(); | |
56 | } | |
57 | ||
58 | template <class T> | |
59 | auto g(T t) -> decltype (t.f()) | |
60 | { | |
61 | return t.f(); | |
62 | } | |
63 | ||
64 | template <class T, class U> | |
65 | auto h(T t, U u) -> decltype (t.template g<U>()) | |
66 | { | |
67 | return t.template g<U>(); | |
68 | } | |
69 | ||
70 | struct D { }; | |
71 | struct C: public A<int>::B<D> | |
72 | { | |
73 | }; | |
74 | ||
75 | template <class T, class U, class V> | |
76 | auto k(T t, U u, V v) -> decltype (t.U::template B<V>::MEM) | |
77 | { | |
78 | return t.U::template B<V>::MEM; | |
79 | } | |
80 | ||
a77f94e2 JM |
81 | // For these two examples we can elide the 'decltype' and just mangle the type. |
82 | template <class T> | |
83 | auto l(T t) -> decltype (t) | |
84 | { | |
85 | return t; | |
86 | } | |
87 | ||
88 | template <class T, T u> | |
89 | auto m(T t) -> decltype (u) | |
90 | { | |
91 | return t; | |
92 | } | |
93 | ||
38179091 | 94 | A<int> a, *p; |
b344d949 JM |
95 | |
96 | int main() | |
97 | { | |
448545cb | 98 | // { dg-final { scan-assembler "_Z3addIidEDTplfp_fp0_ET_T0_" } } |
b344d949 | 99 | auto i = add(1, 2.0); |
448545cb | 100 | // { dg-final { scan-assembler "_Z4add4IidEDTpldecvPT_Li0EdecvPT0_Li0EES0_S2_" } } |
a77f94e2 | 101 | auto i4 = add4(1, 2.0); |
448545cb | 102 | // { dg-final { scan-assembler "_Z4add2IidEDTplcvT__EcvT0__EES0_S1_" } } |
b344d949 | 103 | auto i2 = add2(1, 2.0); |
a3c49752 | 104 | // { dg-final { scan-assembler "_Z4add3IidEDTcl2agfp_fp0_EET_T0_" } } |
b344d949 | 105 | auto i3 = add3(1, 2.0); |
448545cb | 106 | // { dg-final { scan-assembler "_Z1fI1AIiEEDTclptfp_1fEEPT_" } } |
38179091 | 107 | f(p); |
448545cb | 108 | // { dg-final { scan-assembler "_Z1gI1AIiEEDTcldtfp_1fEET_" } } |
38179091 | 109 | g(a); |
448545cb | 110 | // { dg-final { scan-assembler "_Z1hI1AIiEdEDTcldtfp_1gIT0_EEET_S2_" } } |
38179091 | 111 | h(a,1.0); |
448545cb | 112 | // { dg-final { scan-assembler "_Z1kI1C1AIiE1DEDtdtfp_srNT0_1BIT1_EE3MEMET_S4_S6_" } } |
38179091 | 113 | k( C(), A<int>(), D() ); |
a77f94e2 JM |
114 | // { dg-final { scan-assembler "_Z1lIiET_S0_" } } |
115 | l(1); | |
116 | // { dg-final { scan-assembler "_Z1mIiLi1EET_S0_" } } | |
117 | m<int,1>(1); | |
b344d949 | 118 | } |