1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4 template<typename T> class B {
8 template<typename T> struct X : B<T> {
12 int a0[sizeof(X<int>::a) == sizeof(double) ? 1 : -1];
15 template<class T> class Q;
16 template<class T> class R : Q<T> {T current;};
20 template <class T> class Base {
23 static void static_foo();
27 static void static_foo();
31 template <class T> class Derived1 : Base<T> {
34 Base<T>::static_foo();
35 Base<T>::instance_foo();
39 Base<T>::Inner::static_foo();
40 Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
44 Base<T>::static_foo();
45 Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
49 Base<T>::Inner::static_foo();
50 Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
54 template <class T> class Derived2 : Base<T>::Inner {
57 Base<T>::static_foo();
58 Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
62 Base<T>::Inner::static_foo();
63 Base<T>::Inner::instance_foo();
67 Base<T>::static_foo();
68 Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
72 Base<T>::Inner::static_foo();
73 Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
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}}
85 d2.test0(); // expected-note {{in instantiation of member function}}
87 d2.test2(); // expected-note {{in instantiation of member function}}
88 d2.test3(); // expected-note {{in instantiation of member function}}
93 template <class T> struct Base {
94 void foo(T); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
97 template <class T> struct Derived : Base<T> {
99 foo(v); // expected-error {{use of undeclared identifier}}
103 template struct Derived<int>; // expected-note {{requested here}}
113 class MyClass : public MyClassCore<T>
120 // static member declaration
121 static const char* array [N];
124 MyClass<T>::InBase = 17;
128 // static member definition
130 const char* MyClass<T>::array [MyClass<T>::N] = { "A", "B", "C" };
134 inline namespace v1 {
135 template<typename T> struct basic_ostream;
138 template<typename T> struct vector {};
141 template<typename T, typename U> struct pair {};
142 typedef basic_ostream<char> ostream;
144 std::ostream &operator<<(std::ostream &out, const char *);
148 template<typename T> struct A {
151 f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}}
155 void f(int&); // expected-note {{'f' should be declared prior to the call site}}
157 A<int> a; // expected-note {{in instantiation of member function}}
162 template<typename T> int g(T t) {
163 f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}}
167 void f(char&); // expected-note {{'f' should be declared prior to the call site}}
172 int k = N::M::g<char>(0);; // expected-note {{in instantiation of function}}
176 void f(char&); // expected-note {{candidate function not viable}}
178 template<typename T> struct C {
179 static const int n = f(T()); // expected-error {{no matching function}}
183 int f(double); // no note, shadowed by O::f
184 O::C<double> c; // expected-note {{requested here}}
187 // Example from www/compatibility.html
189 template <typename T> T Squared(T x) {
190 return Multiply(x, x); // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
193 int Multiply(int x, int y) { // expected-note {{should be declared prior to the call site}}
198 Squared(5); // expected-note {{here}}
202 // Example from www/compatibility.html
205 void Dump(const T& value) {
206 std::cout << value << "\n"; // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
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";
218 Dump(ns::Data()); // expected-note {{here}}
222 namespace my_file2_a {
224 void Dump(const T &value) {
225 print(std::cout, value); // expected-error 4{{neither visible in the template definition nor found by argument-dependent lookup}}
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}}
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}}
250 T Negate(const T& value) {
251 return !value; // expected-error {{call to function 'operator!' that is neither visible in the template definition nor found by argument-dependent lookup}}
258 ns::Data operator!(ns::Data); // expected-note {{should be declared prior to the call site or in namespace 'PR10053::unary::ns'}}
261 Negate(ns::Data()); // expected-note {{requested here}}
272 __range(a); // expected-error {{undeclared identifier '__range'}}
277 S<int>().f(); // expected-note {{here}}
286 __range(a); // expected-error {{undeclared identifier '__range'}}
291 S<int>().f(); // expected-note {{here}}
301 template<typename T> void g(); // expected-note {{not viable}}
302 template<typename T> void f() {
303 g<int>(T()); // expected-error {{no matching function}}
311 template void f<S>(); // expected-note {{here}}
315 namespace rdar11242625 {
317 template <typename T>
319 struct default_names {
323 template <typename T2 = typename default_names::id>
329 struct Sub : public Main<int> {
333 int arr[sizeof(Sub)];
338 template < unsigned > struct X {
339 static const unsigned dimension = 3;
340 template<unsigned dim=dimension>
341 struct Y: Y<dim> { }; // expected-error{{circular inheritance between 'Y<dim>' and 'Y<dim>'}}
344 X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
347 namespace rdar12629723 {
350 struct C : public C { }; // expected-error{{circular inheritance between 'rdar12629723::X::C' and 'rdar12629723::X::C'}}
354 struct A : public B { // expected-note{{'rdar12629723::X::A' declared here}}
355 virtual void foo() { }
358 struct D : T::foo { };
363 struct X<T>::B : public A { // expected-error{{circular inheritance between 'rdar12629723::X::A' and 'rdar12629723::X::B'}}
364 virtual void foo() { }
368 namespace test_reserved_identifiers {
369 template<typename A, typename B> void tempf(A a, B b) {
370 a + b; // expected-error{{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}}
372 namespace __gnu_cxx { struct X {}; }
373 namespace ns { struct Y {}; }
374 void operator+(__gnu_cxx::X, ns::Y); // expected-note{{or in namespace 'test_reserved_identifiers::ns'}}
378 tempf(x, y); // expected-note{{in instantiation of}}
382 // This test must live in the global namespace.
384 // FIXME: This note is bogus; it is the using directive which would need to move
385 // to prior to the call site to fix the problem.
386 namespace PR14695_A { void PR14695_f(PR14695_X); } // expected-note {{'PR14695_f' should be declared prior to the call site or in the global namespace}}
387 template<typename T> void PR14695_g(T t) { PR14695_f(t); } // expected-error {{call to function 'PR14695_f' that is neither visible in the template definition nor found by argument-dependent lookup}}
388 using namespace PR14695_A;
389 template void PR14695_g(PR14695_X); // expected-note{{requested here}}
391 namespace OperatorNew {
392 template<typename T> void f(T t) {
393 operator new(100, t); // expected-error{{call to function 'operator new' that is neither visible in the template definition nor found by argument-dependent lookup}}
394 // FIXME: This should give the same error.
399 using size_t = decltype(sizeof(0));
400 void *operator new(size_t, OperatorNew::X); // expected-note-re {{should be declared prior to the call site{{$}}}}
401 template void OperatorNew::f(OperatorNew::X); // expected-note {{instantiation of}}
404 template<typename T> decltype(*T()) f() {} // expected-note {{previous}}
405 template<typename T> decltype(T() * T()) g() {} // expected-note {{previous}}
407 // Create some overloaded operators so we build an overload operator call
408 // instead of a builtin operator call for the dependent expression.
413 // Check that they still profile the same.
414 template<typename T> decltype(*T()) f() {} // expected-error {{redefinition}}
415 template<typename T> decltype(T() * T()) g() {} // expected-error {{redefinition}}
418 template <typename> struct CT2 {
419 template <class U> struct X;
421 template <typename T> int CT2<int>::X<>; // expected-error {{template parameter list matching the non-templated nested type 'CT2<int>' should be empty}}