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 {{member is declared here}}
97 template <class T
> struct Derived
: Base
<T
> {
99 foo(v
); // expected-error {{explicit qualification required to use member 'foo' from dependent base class}}
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 int 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'}}
283 __range(a
); // expected-error {{undeclared identifier '__range'}}
288 S
<int>().f(); // expected-note {{here}}
298 template<typename T
> void g(); // expected-note {{not viable}}
299 template<typename T
> void f() {
300 g
<int>(T()); // expected-error {{no matching function}}
308 template void f
<S
>(); // expected-note {{here}}
312 namespace rdar11242625
{
314 template <typename T
>
316 struct default_names
{
320 template <typename T2
= typename
default_names::id
>
326 struct Sub
: public Main
<int> {
330 int arr
[sizeof(Sub
)];
335 template < unsigned > struct X
{
336 static const unsigned dimension
= 3;
337 template<unsigned dim
=dimension
>
338 struct Y
: Y
<dim
> { }; // expected-error{{circular inheritance between 'Y<dim>' and 'Y<dim>'}}
341 X3::Y
<>::iterator it
; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
344 namespace rdar12629723
{
347 struct C
: public C
{ }; // expected-error{{circular inheritance between 'C' and 'rdar12629723::X::C'}}
351 struct A
: public B
{ // expected-note{{'A' declared here}}
352 virtual void foo() { }
355 struct D
: T::foo
{ };
360 struct X
<T
>::B
: public A
{ // expected-error{{circular inheritance between 'A' and 'rdar12629723::X::B'}}
361 virtual void foo() { }
365 namespace test_reserved_identifiers
{
366 template<typename A
, typename B
> void tempf(A a
, B b
) {
367 a
+ b
; // expected-error{{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}}
369 namespace __gnu_cxx
{ struct X
{}; }
370 namespace ns
{ struct Y
{}; }
371 void operator+(__gnu_cxx::X
, ns::Y
); // expected-note{{or in namespace 'test_reserved_identifiers::ns'}}
375 tempf(x
, y
); // expected-note{{in instantiation of}}
379 // This test must live in the global namespace.
381 // FIXME: This note is bogus; it is the using directive which would need to move
382 // to prior to the call site to fix the problem.
383 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}}
384 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}}
385 using namespace PR14695_A
;
386 template void PR14695_g(PR14695_X
); // expected-note{{requested here}}
388 namespace OperatorNew
{
389 template<typename T
> void f(T t
) {
390 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}}
391 // FIXME: This should give the same error.
396 using size_t = decltype(sizeof(0));
397 void *operator new(size_t, OperatorNew::X
); // expected-note-re {{should be declared prior to the call site{{$}}}}
398 template void OperatorNew::f(OperatorNew::X
); // expected-note {{instantiation of}}
401 template<typename T
> decltype(*T()) f() {} // expected-note {{previous}}
402 template<typename T
> decltype(T() * T()) g() {} // expected-note {{previous}}
404 // Create some overloaded operators so we build an overload operator call
405 // instead of a builtin operator call for the dependent expression.
410 // Check that they still profile the same.
411 template<typename T
> decltype(*T()) f() {} // expected-error {{redefinition}}
412 template<typename T
> decltype(T() * T()) g() {} // expected-error {{redefinition}}
415 template <typename
> struct CT2
{
416 template <class U
> struct X
;
418 template <typename T
> int CT2
<int>::X
<>; // expected-error {{template parameter list matching the non-templated nested type 'CT2<int>' should be empty}}
420 namespace DependentTemplateIdWithNoArgs
{
421 template<typename T
> void f() { T::template f(); }
423 template<int = 0> static void f();
428 namespace DependentUnresolvedUsingTemplate
{
432 void f() { this->template foo(); } // expected-error {{does not refer to a template}}
433 void g() { this->template foo
<>(); } // expected-error {{does not refer to a template}}
434 void h() { this->template foo
<int>(); } // expected-error {{does not refer to a template}}
436 struct A
{ template<typename
= int> int foo(); };
437 struct B
{ int foo(); }; // expected-note 3{{non-template here}}
438 void test(X
<A
> xa
, X
<B
> xb
) {
442 xb
.f(); // expected-note {{instantiation of}}
443 xb
.g(); // expected-note {{instantiation of}}
444 xb
.h(); // expected-note {{instantiation of}}
449 template <class a
> struct b
: a
{
451 template<int> int add() { return this->template add(0); }
454 template<typename T
= void> int add(...);
457 int f(b
<a
> ba
) { return ba
.add
<0>(); }