Douglas Gregor | 1edf576 | 2012-06-28 21:43:01 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify -std=c++11 %s |
Chandler Carruth | 03b77b3 | 2011-04-25 06:34:35 +0000 | [diff] [blame] | 2 | |
| 3 | template <class T> |
| 4 | class A { |
| 5 | void foo() { |
| 6 | undeclared(); |
| 7 | } |
Francois Pichet | 8134518 | 2011-09-22 22:14:56 +0000 | [diff] [blame] | 8 | void foo2(); |
Chandler Carruth | 03b77b3 | 2011-04-25 06:34:35 +0000 | [diff] [blame] | 9 | }; |
| 10 | |
| 11 | template <class T> |
| 12 | class B { |
Nico Weber | 71e377d | 2015-01-17 02:33:17 +0000 | [diff] [blame] | 13 | void foo4() { } // expected-note {{previous definition is here}} |
| 14 | void foo4() { } // expected-error {{class member cannot be redeclared}} |
David Majnemer | ea5092a | 2013-07-07 23:49:50 +0000 | [diff] [blame] | 15 | void foo5() { } // expected-note {{previous definition is here}} |
Francois Pichet | 6dc4c16 | 2011-11-18 23:47:17 +0000 | [diff] [blame] | 16 | |
| 17 | friend void foo3() { |
| 18 | undeclared(); |
| 19 | } |
Chandler Carruth | 03b77b3 | 2011-04-25 06:34:35 +0000 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | |
| 23 | template <class T> |
David Majnemer | ea5092a | 2013-07-07 23:49:50 +0000 | [diff] [blame] | 24 | void B<T>::foo5() { // expected-error {{redefinition of 'foo5'}} |
Chandler Carruth | 03b77b3 | 2011-04-25 06:34:35 +0000 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | template <class T> |
| 28 | void A<T>::foo2() { |
| 29 | undeclared(); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | template <class T> |
| 34 | void foo3() { |
| 35 | undeclared(); |
| 36 | } |
| 37 | |
| 38 | template void A<int>::foo2(); |
| 39 | |
| 40 | |
| 41 | void undeclared() |
| 42 | { |
| 43 | |
| 44 | } |
| 45 | |
| 46 | template <class T> void foo5() {} //expected-note {{previous definition is here}} |
| 47 | template <class T> void foo5() {} // expected-error {{redefinition of 'foo5'}} |
Francois Pichet | 8134518 | 2011-09-22 22:14:56 +0000 | [diff] [blame] | 48 | |
| 49 | |
| 50 | |
| 51 | namespace Inner_Outer_same_template_param_name { |
| 52 | |
| 53 | template <class T> |
| 54 | class Outmost { |
| 55 | public: |
| 56 | template <class T> |
| 57 | class Inner { |
| 58 | public: |
| 59 | void f() { |
| 60 | T* var; |
| 61 | } |
| 62 | }; |
| 63 | }; |
| 64 | |
| 65 | } |
| 66 | |
Francois Pichet | e666476 | 2012-02-22 08:25:53 +0000 | [diff] [blame] | 67 | |
| 68 | namespace PR11931 { |
| 69 | |
| 70 | template <typename RunType> |
| 71 | struct BindState; |
| 72 | |
| 73 | template<> |
| 74 | struct BindState<void(void*)> { |
| 75 | static void Run() { } |
| 76 | }; |
| 77 | |
| 78 | class Callback { |
| 79 | public: |
| 80 | typedef void RunType(); |
| 81 | |
| 82 | template <typename RunType> |
| 83 | Callback(BindState<RunType> bind_state) { |
| 84 | BindState<RunType>::Run(); |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | |
| 89 | Callback Bind() { |
| 90 | return Callback(BindState<void(void*)>()); |
| 91 | } |
| 92 | |
| 93 | } |
Douglas Gregor | 1edf576 | 2012-06-28 21:43:01 +0000 | [diff] [blame] | 94 | |
| 95 | namespace rdar11700604 { |
| 96 | template<typename T> void foo() = delete; |
| 97 | |
| 98 | struct X { |
| 99 | X() = default; |
| 100 | |
| 101 | template<typename T> void foo() = delete; |
| 102 | }; |
| 103 | } |
| 104 | |
David Majnemer | c185aa7 | 2013-09-27 04:14:12 +0000 | [diff] [blame] | 105 | namespace PR17334 { |
| 106 | |
| 107 | template <typename = void> struct ArrayRef { |
| 108 | constexpr ArrayRef() {} |
| 109 | }; |
| 110 | template <typename = void> void CreateConstInBoundsGEP2_32() { |
| 111 | ArrayRef<> IdxList; |
| 112 | } |
| 113 | void LLVMBuildStructGEP() { CreateConstInBoundsGEP2_32(); } |
| 114 | |
| 115 | } |
| 116 | |
David Majnemer | c85ed7e | 2013-10-23 21:31:20 +0000 | [diff] [blame] | 117 | namespace PR17661 { |
| 118 | template <typename T> |
| 119 | constexpr T Fun(T A) { return T(0); } |
| 120 | |
| 121 | constexpr int Var = Fun(20); |
| 122 | } |
| 123 | |
Richard Smith | 8e6002f | 2014-03-12 23:14:33 +0000 | [diff] [blame] | 124 | template <typename T> |
| 125 | auto invalidTrailingRetType() -> Bogus {} // expected-error {{unknown type name 'Bogus'}} |
Hans Wennborg | b6d4e8c | 2014-05-02 02:01:07 +0000 | [diff] [blame] | 126 | |
| 127 | namespace PR19613 { |
| 128 | |
| 129 | struct HeapTypeConfig { |
| 130 | static void from_bitset(); |
| 131 | }; |
| 132 | |
| 133 | template <class Config> |
| 134 | struct TypeImpl { |
| 135 | struct BitsetType; |
| 136 | |
| 137 | static void Any() { |
| 138 | BitsetType::New(); |
| 139 | } |
| 140 | }; |
| 141 | |
| 142 | template<class Config> |
| 143 | struct TypeImpl<Config>::BitsetType { |
| 144 | static void New() { |
| 145 | Config::from_bitset(); |
| 146 | } |
| 147 | }; |
| 148 | |
| 149 | static void f() { |
| 150 | TypeImpl<HeapTypeConfig>::Any(); |
| 151 | } |
| 152 | |
| 153 | template<typename A> struct S { |
| 154 | template<typename B> struct T; |
| 155 | }; |
| 156 | template<typename A> template<typename B> struct S<A>::T { |
| 157 | template<typename C, typename D> struct U; |
| 158 | template<typename C> struct U<C, C> { |
| 159 | template<typename E> static int f() { |
| 160 | return sizeof(A) + sizeof(B) + sizeof(C) + sizeof(E); |
| 161 | } |
| 162 | }; |
| 163 | }; |
| 164 | |
| 165 | static void g() { |
| 166 | S<int>::T<int>::U<int,int>::f<int>(); |
| 167 | } |
| 168 | |
| 169 | template<typename T> struct SS { |
| 170 | template<typename U> struct X; |
| 171 | template<typename U> struct X<U*>; |
| 172 | }; |
| 173 | template<typename T> template<typename U> struct SS<T>::X<U*> { |
| 174 | static int f() { |
| 175 | return sizeof(T) + sizeof(U); |
| 176 | } |
| 177 | }; |
| 178 | |
| 179 | static void h() { |
| 180 | SS<int>::X<int*>::f(); |
| 181 | } |
| 182 | |
| 183 | } |