Richard Smith | f50e88a | 2011-06-05 22:42:48 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s |
Anders Carlsson | 1d79faf | 2009-06-12 18:53:02 +0000 | [diff] [blame] | 2 | |
| 3 | typedef double A; |
| 4 | template<typename T> class B { |
| 5 | typedef int A; |
| 6 | }; |
| 7 | |
| 8 | template<typename T> struct X : B<T> { |
| 9 | static A a; |
| 10 | }; |
| 11 | |
| 12 | int a0[sizeof(X<int>::a) == sizeof(double) ? 1 : -1]; |
| 13 | |
| 14 | // PR4365. |
| 15 | template<class T> class Q; |
| 16 | template<class T> class R : Q<T> {T current;}; |
John McCall | 2641606 | 2009-11-24 20:33:45 +0000 | [diff] [blame] | 17 | |
| 18 | |
| 19 | namespace test0 { |
| 20 | template <class T> class Base { |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 21 | public: |
John McCall | 2641606 | 2009-11-24 20:33:45 +0000 | [diff] [blame] | 22 | void instance_foo(); |
| 23 | static void static_foo(); |
| 24 | class Inner { |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 25 | public: |
John McCall | 2641606 | 2009-11-24 20:33:45 +0000 | [diff] [blame] | 26 | void instance_foo(); |
| 27 | static void static_foo(); |
| 28 | }; |
| 29 | }; |
| 30 | |
| 31 | template <class T> class Derived1 : Base<T> { |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 32 | public: |
John McCall | 2641606 | 2009-11-24 20:33:45 +0000 | [diff] [blame] | 33 | void test0() { |
| 34 | Base<T>::static_foo(); |
| 35 | Base<T>::instance_foo(); |
| 36 | } |
| 37 | |
| 38 | void test1() { |
| 39 | Base<T>::Inner::static_foo(); |
| 40 | Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}} |
| 41 | } |
| 42 | |
| 43 | static void test2() { |
| 44 | Base<T>::static_foo(); |
| 45 | Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}} |
| 46 | } |
| 47 | |
| 48 | static void test3() { |
| 49 | Base<T>::Inner::static_foo(); |
| 50 | Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}} |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | template <class T> class Derived2 : Base<T>::Inner { |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 55 | public: |
John McCall | 2641606 | 2009-11-24 20:33:45 +0000 | [diff] [blame] | 56 | void test0() { |
| 57 | Base<T>::static_foo(); |
| 58 | Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}} |
| 59 | } |
| 60 | |
| 61 | void test1() { |
| 62 | Base<T>::Inner::static_foo(); |
| 63 | Base<T>::Inner::instance_foo(); |
| 64 | } |
| 65 | |
| 66 | static void test2() { |
| 67 | Base<T>::static_foo(); |
| 68 | Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}} |
| 69 | } |
| 70 | |
| 71 | static void test3() { |
| 72 | Base<T>::Inner::static_foo(); |
| 73 | Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}} |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | void test0() { |
| 78 | Derived1<int> d1; |
| 79 | d1.test0(); |
| 80 | d1.test1(); // expected-note {{in instantiation of member function}} |
| 81 | d1.test2(); // expected-note {{in instantiation of member function}} |
| 82 | d1.test3(); // expected-note {{in instantiation of member function}} |
| 83 | |
| 84 | Derived2<int> d2; |
| 85 | d2.test0(); // expected-note {{in instantiation of member function}} |
| 86 | d2.test1(); |
| 87 | d2.test2(); // expected-note {{in instantiation of member function}} |
| 88 | d2.test3(); // expected-note {{in instantiation of member function}} |
| 89 | } |
| 90 | } |
John McCall | 578b69b | 2009-12-16 08:11:27 +0000 | [diff] [blame] | 91 | |
| 92 | namespace test1 { |
| 93 | template <class T> struct Base { |
| 94 | void foo(T); // expected-note {{must qualify identifier to find this declaration in dependent base class}} |
| 95 | }; |
| 96 | |
| 97 | template <class T> struct Derived : Base<T> { |
| 98 | void doFoo(T v) { |
John McCall | 3b4294e | 2009-12-16 12:17:52 +0000 | [diff] [blame] | 99 | foo(v); // expected-error {{use of undeclared identifier}} |
John McCall | 578b69b | 2009-12-16 08:11:27 +0000 | [diff] [blame] | 100 | } |
| 101 | }; |
| 102 | |
| 103 | template struct Derived<int>; // expected-note {{requested here}} |
| 104 | } |
Douglas Gregor | 2f9f89c | 2011-02-04 13:35:07 +0000 | [diff] [blame] | 105 | |
| 106 | namespace PR8966 { |
| 107 | template <class T> |
| 108 | class MyClassCore |
| 109 | { |
| 110 | }; |
| 111 | |
| 112 | template <class T> |
| 113 | class MyClass : public MyClassCore<T> |
| 114 | { |
| 115 | public: |
| 116 | enum { |
| 117 | N |
| 118 | }; |
| 119 | |
| 120 | // static member declaration |
| 121 | static const char* array [N]; |
| 122 | |
| 123 | void f() { |
| 124 | MyClass<T>::InBase = 17; |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | // static member definition |
| 129 | template <class T> |
| 130 | const char* MyClass<T>::array [MyClass<T>::N] = { "A", "B", "C" }; |
| 131 | } |
Richard Smith | f50e88a | 2011-06-05 22:42:48 +0000 | [diff] [blame] | 132 | |
| 133 | namespace std { |
| 134 | inline namespace v1 { |
| 135 | template<typename T> struct basic_ostream; |
| 136 | } |
| 137 | namespace inner { |
| 138 | template<typename T> struct vector {}; |
| 139 | } |
| 140 | using inner::vector; |
| 141 | template<typename T, typename U> struct pair {}; |
| 142 | typedef basic_ostream<char> ostream; |
| 143 | extern ostream cout; |
| 144 | std::ostream &operator<<(std::ostream &out, const char *); |
| 145 | } |
| 146 | |
| 147 | namespace PR10053 { |
| 148 | template<typename T> struct A { |
| 149 | T t; |
| 150 | A() { |
Jay Foad | 2a00b83 | 2011-06-14 12:59:25 +0000 | [diff] [blame^] | 151 | f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}} |
Richard Smith | f50e88a | 2011-06-05 22:42:48 +0000 | [diff] [blame] | 152 | } |
| 153 | }; |
| 154 | |
| 155 | void f(int&); // expected-note {{'f' should be declared prior to the call site}} |
| 156 | |
| 157 | A<int> a; // expected-note {{in instantiation of member function}} |
| 158 | |
| 159 | |
| 160 | namespace N { |
| 161 | namespace M { |
| 162 | template<typename T> int g(T t) { |
Jay Foad | 2a00b83 | 2011-06-14 12:59:25 +0000 | [diff] [blame^] | 163 | f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}} |
Richard Smith | f50e88a | 2011-06-05 22:42:48 +0000 | [diff] [blame] | 164 | }; |
| 165 | } |
| 166 | |
| 167 | void f(char&); // expected-note {{'f' should be declared prior to the call site}} |
| 168 | } |
| 169 | |
| 170 | void f(char&); |
| 171 | |
| 172 | int k = N::M::g<char>(0);; // expected-note {{in instantiation of function}} |
| 173 | |
| 174 | |
| 175 | namespace O { |
| 176 | void f(char&); // expected-note {{candidate function not viable}} |
| 177 | |
| 178 | template<typename T> struct C { |
| 179 | static const int n = f(T()); // expected-error {{no matching function}} |
| 180 | }; |
| 181 | } |
| 182 | |
| 183 | int f(double); // no note, shadowed by O::f |
| 184 | O::C<double> c; // expected-note {{requested here}} |
| 185 | |
| 186 | |
| 187 | // Example from www/compatibility.html |
| 188 | namespace my_file { |
| 189 | template <typename T> T Squared(T x) { |
Jay Foad | 2a00b83 | 2011-06-14 12:59:25 +0000 | [diff] [blame^] | 190 | return Multiply(x, x); // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}} |
Richard Smith | f50e88a | 2011-06-05 22:42:48 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | int Multiply(int x, int y) { // expected-note {{should be declared prior to the call site}} |
| 194 | return x * y; |
| 195 | } |
| 196 | |
| 197 | int main() { |
| 198 | Squared(5); // expected-note {{here}} |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | // Example from www/compatibility.html |
| 203 | namespace my_file2 { |
| 204 | template<typename T> |
| 205 | void Dump(const T& value) { |
Jay Foad | 2a00b83 | 2011-06-14 12:59:25 +0000 | [diff] [blame^] | 206 | std::cout << value << "\n"; // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}} |
Richard Smith | f50e88a | 2011-06-05 22:42:48 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | namespace ns { |
| 210 | struct Data {}; |
| 211 | } |
| 212 | |
| 213 | std::ostream& operator<<(std::ostream& out, ns::Data data) { // expected-note {{should be declared prior to the call site or in namespace 'PR10053::my_file2::ns'}} |
| 214 | return out << "Some data"; |
| 215 | } |
| 216 | |
| 217 | void Use() { |
| 218 | Dump(ns::Data()); // expected-note {{here}} |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | namespace my_file2_a { |
| 223 | template<typename T> |
| 224 | void Dump(const T &value) { |
Jay Foad | 2a00b83 | 2011-06-14 12:59:25 +0000 | [diff] [blame^] | 225 | print(std::cout, value); // expected-error 4{{neither visible in the template definition nor found by argument-dependent lookup}} |
Richard Smith | f50e88a | 2011-06-05 22:42:48 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | namespace ns { |
| 229 | struct Data {}; |
| 230 | } |
| 231 | namespace ns2 { |
| 232 | struct Data {}; |
| 233 | } |
| 234 | |
| 235 | std::ostream &print(std::ostream &out, int); // expected-note-re {{should be declared prior to the call site$}} |
| 236 | std::ostream &print(std::ostream &out, ns::Data); // expected-note {{should be declared prior to the call site or in namespace 'PR10053::my_file2_a::ns'}} |
| 237 | std::ostream &print(std::ostream &out, std::vector<ns2::Data>); // expected-note {{should be declared prior to the call site or in namespace 'PR10053::my_file2_a::ns2'}} |
| 238 | std::ostream &print(std::ostream &out, std::pair<ns::Data, ns2::Data>); // expected-note {{should be declared prior to the call site or in an associated namespace of one of its arguments}} |
| 239 | |
| 240 | void Use() { |
| 241 | Dump(0); // expected-note {{requested here}} |
| 242 | Dump(ns::Data()); // expected-note {{requested here}} |
| 243 | Dump(std::vector<ns2::Data>()); // expected-note {{requested here}} |
| 244 | Dump(std::pair<ns::Data, ns2::Data>()); // expected-note {{requested here}} |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | namespace unary { |
| 249 | template<typename T> |
| 250 | T Negate(const T& value) { |
Jay Foad | 2a00b83 | 2011-06-14 12:59:25 +0000 | [diff] [blame^] | 251 | return !value; // expected-error {{call to function 'operator!' that is neither visible in the template definition nor found by argument-dependent lookup}} |
Richard Smith | f50e88a | 2011-06-05 22:42:48 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | namespace ns { |
| 255 | struct Data {}; |
| 256 | } |
| 257 | |
| 258 | ns::Data operator!(ns::Data); // expected-note {{should be declared prior to the call site or in namespace 'PR10053::unary::ns'}} |
| 259 | |
| 260 | void Use() { |
| 261 | Negate(ns::Data()); // expected-note {{requested here}} |
| 262 | } |
| 263 | } |
| 264 | } |