]>
Commit | Line | Data |
---|---|---|
38179091 | 1 | // Tests for late-specified return type. |
4b2e63de JM |
2 | // { dg-do compile { target c++11 } } |
3 | // { dg-options "-fabi-version=5" } | |
f57ca1ea JM |
4 | |
5 | auto f() -> int | |
6 | { | |
7 | return 0; | |
8 | } | |
9 | ||
10 | template<class T, class U> | |
18802917 JM |
11 | auto add(T t, U u) -> decltype (t+u) |
12 | { | |
13 | return t+u; | |
14 | } | |
b344d949 JM |
15 | |
16 | template<class T, class U> | |
38179091 JM |
17 | decltype(T()+U()) add2(T t, U u) |
18 | { | |
19 | return t+u; | |
20 | } | |
b344d949 JM |
21 | |
22 | template <class T, class U> | |
38179091 JM |
23 | U ag (T, U) |
24 | { | |
25 | return U(); | |
26 | } | |
b344d949 JM |
27 | |
28 | template<class T, class U> | |
38179091 JM |
29 | auto add3(T t, U u) -> decltype (ag(t,u)) |
30 | { | |
31 | return ag(t,u); | |
32 | } | |
33 | ||
a77f94e2 JM |
34 | template<class T, class U> |
35 | decltype(*(T*)0+*(U*)0) add4(T t, U u) | |
36 | { | |
37 | return t+u; | |
38 | } | |
39 | ||
38179091 JM |
40 | template <class T> |
41 | struct A | |
42 | { | |
19520957 | 43 | T f() { return T(); } |
38179091 | 44 | template <class U> |
19520957 | 45 | T g() { return T(); } |
38179091 JM |
46 | template <class V> |
47 | struct B | |
48 | { | |
49 | int MEM; | |
50 | }; | |
51 | }; | |
52 | ||
53 | template <class T> | |
54 | auto f(T* t) -> decltype (t->f()) | |
55 | { | |
56 | return t->f(); | |
57 | } | |
58 | ||
59 | template <class T> | |
60 | auto g(T t) -> decltype (t.f()) | |
61 | { | |
62 | return t.f(); | |
63 | } | |
64 | ||
65 | template <class T, class U> | |
66 | auto h(T t, U u) -> decltype (t.template g<U>()) | |
67 | { | |
68 | return t.template g<U>(); | |
69 | } | |
70 | ||
71 | struct D { }; | |
72 | struct C: public A<int>::B<D> | |
73 | { | |
74 | }; | |
75 | ||
76 | template <class T, class U, class V> | |
77 | auto k(T t, U u, V v) -> decltype (t.U::template B<V>::MEM) | |
78 | { | |
79 | return t.U::template B<V>::MEM; | |
80 | } | |
81 | ||
a77f94e2 JM |
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() ); |
67e18edb | 114 | // { dg-final { scan-assembler "_Z1lIiEDtfp_ET_" } } |
a77f94e2 | 115 | l(1); |
67e18edb | 116 | // { dg-final { scan-assembler "_Z1mIiLi1EEDtT0_ET_" } } |
a77f94e2 | 117 | m<int,1>(1); |
b344d949 | 118 | } |