Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 1 | // Header for PCH test cxx-templates.cpp |
| 2 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3 | template <typename T1, typename T2> |
Argyrios Kyrtzidis | 5a7b9c5 | 2010-07-02 11:55:48 +0000 | [diff] [blame] | 4 | struct S; |
| 5 | |
| 6 | template <typename T1, typename T2> |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 7 | struct S { |
Argyrios Kyrtzidis | 5a7b9c5 | 2010-07-02 11:55:48 +0000 | [diff] [blame] | 8 | S() { } |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 9 | static void templ(); |
| 10 | }; |
| 11 | |
| 12 | template <typename T> |
| 13 | struct S<int, T> { |
| 14 | static void partial(); |
| 15 | }; |
| 16 | |
| 17 | template <> |
| 18 | struct S<int, float> { |
| 19 | static void explicit_special(); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 20 | }; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 21 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 22 | template <int x> |
| 23 | int tmpl_f2() { return x; } |
| 24 | |
Argyrios Kyrtzidis | b24e199 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 25 | template <typename T, int y> |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 26 | T templ_f(T x) { |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 27 | int z = templ_f<int, 5>(3); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 28 | z = tmpl_f2<y+2>(); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 29 | T data[y]; |
Argyrios Kyrtzidis | b24e199 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 30 | return x+y; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 31 | } |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 32 | |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 33 | void govl(int); |
| 34 | void govl(char); |
| 35 | |
| 36 | template <typename T> |
| 37 | struct Unresolv { |
| 38 | void f() { |
| 39 | govl(T()); |
| 40 | } |
| 41 | }; |
| 42 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 43 | template <typename T> |
| 44 | struct Dep { |
| 45 | typedef typename T::type Ty; |
| 46 | void f() { |
| 47 | Ty x = Ty(); |
| 48 | T::my_f(); |
| 49 | int y = T::template my_templf<int>(0); |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 50 | ovl(y); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 51 | } |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 52 | |
| 53 | void ovl(int); |
| 54 | void ovl(float); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | template<typename T, typename A1> |
| 58 | inline T make_a(const A1& a1) { |
Argyrios Kyrtzidis | 12dffcd | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 59 | T::depend_declref(); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 60 | return T(a1); |
| 61 | } |
Argyrios Kyrtzidis | 8f4eae9 | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 62 | |
| 63 | template <class T> class UseBase { |
| 64 | void foo(); |
| 65 | typedef int bar; |
| 66 | }; |
| 67 | |
| 68 | template <class T> class UseA : public UseBase<T> { |
| 69 | using UseBase<T>::foo; |
| 70 | using typename UseBase<T>::bar; |
| 71 | }; |
Argyrios Kyrtzidis | 5a7b9c5 | 2010-07-02 11:55:48 +0000 | [diff] [blame] | 72 | |
| 73 | template <class T> class Sub : public UseBase<int> { }; |
| 74 | |
| 75 | template <class _Ret, class _Tp> |
| 76 | class mem_fun_t |
| 77 | { |
| 78 | public: |
| 79 | explicit |
| 80 | mem_fun_t(_Ret (_Tp::*__pf)()) |
| 81 | {} |
| 82 | |
| 83 | private: |
| 84 | _Ret (_Tp::*_M_f)(); |
| 85 | }; |
| 86 | |
| 87 | template<unsigned N> |
| 88 | bool isInt(int x); |
| 89 | |
| 90 | template<> bool isInt<8>(int x) { |
Argyrios Kyrtzidis | 7cb45e3 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 91 | try { ++x; } catch(...) { --x; } |
| 92 | return true; |
Argyrios Kyrtzidis | 5a7b9c5 | 2010-07-02 11:55:48 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | template<typename _CharT> |
| 96 | int __copy_streambufs_eof(_CharT); |
| 97 | |
| 98 | class basic_streambuf |
| 99 | { |
| 100 | void m() { } |
| 101 | friend int __copy_streambufs_eof<>(int); |
| 102 | }; |
| 103 | |
Argyrios Kyrtzidis | e3041be | 2010-07-19 10:14:41 +0000 | [diff] [blame] | 104 | // PR 7660 |
| 105 | template<typename T> struct S_PR7660 { void g(void (*)(T)); }; |
| 106 | template<> void S_PR7660<int>::g(void(*)(int)) {} |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 107 | |
| 108 | // PR 7670 |
| 109 | template<typename> class C_PR7670; |
| 110 | template<> class C_PR7670<int>; |
| 111 | template<> class C_PR7670<int>; |
Argyrios Kyrtzidis | ab411c8 | 2010-07-29 20:07:52 +0000 | [diff] [blame] | 112 | |
| 113 | template <bool B> |
| 114 | struct S2 { |
| 115 | static bool V; |
| 116 | }; |
| 117 | |
| 118 | extern template class S2<true>; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame^] | 119 | |
| 120 | template <typename T> |
| 121 | struct S3 { |
| 122 | void m(); |
| 123 | }; |
| 124 | |
| 125 | template <typename T> |
| 126 | inline void S3<T>::m() { } |