xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/dependent-names.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc typedef double A;
4f4a2713aSLionel Sambuc template<typename T> class B {
5f4a2713aSLionel Sambuc   typedef int A;
6f4a2713aSLionel Sambuc };
7f4a2713aSLionel Sambuc 
8f4a2713aSLionel Sambuc template<typename T> struct X : B<T> {
9f4a2713aSLionel Sambuc   static A a;
10f4a2713aSLionel Sambuc };
11f4a2713aSLionel Sambuc 
12f4a2713aSLionel Sambuc int a0[sizeof(X<int>::a) == sizeof(double) ? 1 : -1];
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc // PR4365.
15f4a2713aSLionel Sambuc template<class T> class Q;
16f4a2713aSLionel Sambuc template<class T> class R : Q<T> {T current;};
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc namespace test0 {
20f4a2713aSLionel Sambuc   template <class T> class Base {
21f4a2713aSLionel Sambuc   public:
22f4a2713aSLionel Sambuc     void instance_foo();
23f4a2713aSLionel Sambuc     static void static_foo();
24f4a2713aSLionel Sambuc     class Inner {
25f4a2713aSLionel Sambuc     public:
26f4a2713aSLionel Sambuc       void instance_foo();
27f4a2713aSLionel Sambuc       static void static_foo();
28f4a2713aSLionel Sambuc     };
29f4a2713aSLionel Sambuc   };
30f4a2713aSLionel Sambuc 
31f4a2713aSLionel Sambuc   template <class T> class Derived1 : Base<T> {
32f4a2713aSLionel Sambuc   public:
test0()33f4a2713aSLionel Sambuc     void test0() {
34f4a2713aSLionel Sambuc       Base<T>::static_foo();
35f4a2713aSLionel Sambuc       Base<T>::instance_foo();
36f4a2713aSLionel Sambuc     }
37f4a2713aSLionel Sambuc 
test1()38f4a2713aSLionel Sambuc     void test1() {
39f4a2713aSLionel Sambuc       Base<T>::Inner::static_foo();
40f4a2713aSLionel Sambuc       Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
41f4a2713aSLionel Sambuc     }
42f4a2713aSLionel Sambuc 
test2()43f4a2713aSLionel Sambuc     static void test2() {
44f4a2713aSLionel Sambuc       Base<T>::static_foo();
45f4a2713aSLionel Sambuc       Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
46f4a2713aSLionel Sambuc     }
47f4a2713aSLionel Sambuc 
test3()48f4a2713aSLionel Sambuc     static void test3() {
49f4a2713aSLionel Sambuc       Base<T>::Inner::static_foo();
50f4a2713aSLionel Sambuc       Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
51f4a2713aSLionel Sambuc     }
52f4a2713aSLionel Sambuc   };
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc   template <class T> class Derived2 : Base<T>::Inner {
55f4a2713aSLionel Sambuc   public:
test0()56f4a2713aSLionel Sambuc     void test0() {
57f4a2713aSLionel Sambuc       Base<T>::static_foo();
58f4a2713aSLionel Sambuc       Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
59f4a2713aSLionel Sambuc     }
60f4a2713aSLionel Sambuc 
test1()61f4a2713aSLionel Sambuc     void test1() {
62f4a2713aSLionel Sambuc       Base<T>::Inner::static_foo();
63f4a2713aSLionel Sambuc       Base<T>::Inner::instance_foo();
64f4a2713aSLionel Sambuc     }
65f4a2713aSLionel Sambuc 
test2()66f4a2713aSLionel Sambuc     static void test2() {
67f4a2713aSLionel Sambuc       Base<T>::static_foo();
68f4a2713aSLionel Sambuc       Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
69f4a2713aSLionel Sambuc     }
70f4a2713aSLionel Sambuc 
test3()71f4a2713aSLionel Sambuc     static void test3() {
72f4a2713aSLionel Sambuc       Base<T>::Inner::static_foo();
73f4a2713aSLionel Sambuc       Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
74f4a2713aSLionel Sambuc     }
75f4a2713aSLionel Sambuc   };
76f4a2713aSLionel Sambuc 
test0()77f4a2713aSLionel Sambuc   void test0() {
78f4a2713aSLionel Sambuc     Derived1<int> d1;
79f4a2713aSLionel Sambuc     d1.test0();
80f4a2713aSLionel Sambuc     d1.test1(); // expected-note {{in instantiation of member function}}
81f4a2713aSLionel Sambuc     d1.test2(); // expected-note {{in instantiation of member function}}
82f4a2713aSLionel Sambuc     d1.test3(); // expected-note {{in instantiation of member function}}
83f4a2713aSLionel Sambuc 
84f4a2713aSLionel Sambuc     Derived2<int> d2;
85f4a2713aSLionel Sambuc     d2.test0(); // expected-note {{in instantiation of member function}}
86f4a2713aSLionel Sambuc     d2.test1();
87f4a2713aSLionel Sambuc     d2.test2(); // expected-note {{in instantiation of member function}}
88f4a2713aSLionel Sambuc     d2.test3(); // expected-note {{in instantiation of member function}}
89f4a2713aSLionel Sambuc   }
90f4a2713aSLionel Sambuc }
91f4a2713aSLionel Sambuc 
92f4a2713aSLionel Sambuc namespace test1 {
93f4a2713aSLionel Sambuc   template <class T> struct Base {
94f4a2713aSLionel Sambuc     void foo(T); // expected-note {{must qualify identifier to find this declaration in dependent base class}}
95f4a2713aSLionel Sambuc   };
96f4a2713aSLionel Sambuc 
97f4a2713aSLionel Sambuc   template <class T> struct Derived : Base<T> {
doFootest1::Derived98f4a2713aSLionel Sambuc     void doFoo(T v) {
99f4a2713aSLionel Sambuc       foo(v); // expected-error {{use of undeclared identifier}}
100f4a2713aSLionel Sambuc     }
101f4a2713aSLionel Sambuc   };
102f4a2713aSLionel Sambuc 
103f4a2713aSLionel Sambuc   template struct Derived<int>; // expected-note {{requested here}}
104f4a2713aSLionel Sambuc }
105f4a2713aSLionel Sambuc 
106f4a2713aSLionel Sambuc namespace PR8966 {
107f4a2713aSLionel Sambuc   template <class T>
108f4a2713aSLionel Sambuc   class MyClassCore
109f4a2713aSLionel Sambuc   {
110f4a2713aSLionel Sambuc   };
111f4a2713aSLionel Sambuc 
112f4a2713aSLionel Sambuc   template <class T>
113f4a2713aSLionel Sambuc   class MyClass : public MyClassCore<T>
114f4a2713aSLionel Sambuc   {
115f4a2713aSLionel Sambuc   public:
116f4a2713aSLionel Sambuc     enum  {
117f4a2713aSLionel Sambuc       N
118f4a2713aSLionel Sambuc     };
119f4a2713aSLionel Sambuc 
120f4a2713aSLionel Sambuc     // static member declaration
121f4a2713aSLionel Sambuc     static const char* array [N];
122f4a2713aSLionel Sambuc 
f()123f4a2713aSLionel Sambuc     void f() {
124f4a2713aSLionel Sambuc       MyClass<T>::InBase = 17;
125f4a2713aSLionel Sambuc     }
126f4a2713aSLionel Sambuc   };
127f4a2713aSLionel Sambuc 
128f4a2713aSLionel Sambuc   // static member definition
129f4a2713aSLionel Sambuc   template <class T>
130f4a2713aSLionel Sambuc   const char* MyClass<T>::array [MyClass<T>::N] = { "A", "B", "C" };
131f4a2713aSLionel Sambuc }
132f4a2713aSLionel Sambuc 
133f4a2713aSLionel Sambuc namespace std {
134f4a2713aSLionel Sambuc   inline namespace v1 {
135f4a2713aSLionel Sambuc     template<typename T> struct basic_ostream;
136f4a2713aSLionel Sambuc   }
137f4a2713aSLionel Sambuc   namespace inner {
138f4a2713aSLionel Sambuc     template<typename T> struct vector {};
139f4a2713aSLionel Sambuc   }
140f4a2713aSLionel Sambuc   using inner::vector;
141f4a2713aSLionel Sambuc   template<typename T, typename U> struct pair {};
142f4a2713aSLionel Sambuc   typedef basic_ostream<char> ostream;
143f4a2713aSLionel Sambuc   extern ostream cout;
144f4a2713aSLionel Sambuc   std::ostream &operator<<(std::ostream &out, const char *);
145f4a2713aSLionel Sambuc }
146f4a2713aSLionel Sambuc 
147f4a2713aSLionel Sambuc namespace PR10053 {
148f4a2713aSLionel Sambuc   template<typename T> struct A {
149f4a2713aSLionel Sambuc     T t;
APR10053::A150f4a2713aSLionel Sambuc     A() {
151f4a2713aSLionel Sambuc       f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}}
152f4a2713aSLionel Sambuc     }
153f4a2713aSLionel Sambuc   };
154f4a2713aSLionel Sambuc 
155f4a2713aSLionel Sambuc   void f(int&); // expected-note {{'f' should be declared prior to the call site}}
156f4a2713aSLionel Sambuc 
157f4a2713aSLionel Sambuc   A<int> a; // expected-note {{in instantiation of member function}}
158f4a2713aSLionel Sambuc 
159f4a2713aSLionel Sambuc 
160f4a2713aSLionel Sambuc   namespace N {
161f4a2713aSLionel Sambuc     namespace M {
g(T t)162f4a2713aSLionel Sambuc       template<typename T> int g(T t) {
163f4a2713aSLionel Sambuc         f(t); // expected-error {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}}
164f4a2713aSLionel Sambuc       };
165f4a2713aSLionel Sambuc     }
166f4a2713aSLionel Sambuc 
167f4a2713aSLionel Sambuc     void f(char&); // expected-note {{'f' should be declared prior to the call site}}
168f4a2713aSLionel Sambuc   }
169f4a2713aSLionel Sambuc 
170f4a2713aSLionel Sambuc   void f(char&);
171f4a2713aSLionel Sambuc 
172f4a2713aSLionel Sambuc   int k = N::M::g<char>(0);; // expected-note {{in instantiation of function}}
173f4a2713aSLionel Sambuc 
174f4a2713aSLionel Sambuc 
175f4a2713aSLionel Sambuc   namespace O {
176f4a2713aSLionel Sambuc     void f(char&); // expected-note {{candidate function not viable}}
177f4a2713aSLionel Sambuc 
178f4a2713aSLionel Sambuc     template<typename T> struct C {
179f4a2713aSLionel Sambuc       static const int n = f(T()); // expected-error {{no matching function}}
180f4a2713aSLionel Sambuc     };
181f4a2713aSLionel Sambuc   }
182f4a2713aSLionel Sambuc 
183f4a2713aSLionel Sambuc   int f(double); // no note, shadowed by O::f
184f4a2713aSLionel Sambuc   O::C<double> c; // expected-note {{requested here}}
185f4a2713aSLionel Sambuc 
186f4a2713aSLionel Sambuc 
187f4a2713aSLionel Sambuc   // Example from www/compatibility.html
188f4a2713aSLionel Sambuc   namespace my_file {
Squared(T x)189f4a2713aSLionel Sambuc     template <typename T> T Squared(T x) {
190f4a2713aSLionel Sambuc       return Multiply(x, x); // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
191f4a2713aSLionel Sambuc     }
192f4a2713aSLionel Sambuc 
Multiply(int x,int y)193f4a2713aSLionel Sambuc     int Multiply(int x, int y) { // expected-note {{should be declared prior to the call site}}
194f4a2713aSLionel Sambuc       return x * y;
195f4a2713aSLionel Sambuc     }
196f4a2713aSLionel Sambuc 
main()197f4a2713aSLionel Sambuc     int main() {
198f4a2713aSLionel Sambuc       Squared(5); // expected-note {{here}}
199f4a2713aSLionel Sambuc     }
200f4a2713aSLionel Sambuc   }
201f4a2713aSLionel Sambuc 
202f4a2713aSLionel Sambuc   // Example from www/compatibility.html
203f4a2713aSLionel Sambuc   namespace my_file2 {
204f4a2713aSLionel Sambuc     template<typename T>
Dump(const T & value)205f4a2713aSLionel Sambuc     void Dump(const T& value) {
206f4a2713aSLionel Sambuc       std::cout << value << "\n"; // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
207f4a2713aSLionel Sambuc     }
208f4a2713aSLionel Sambuc 
209f4a2713aSLionel Sambuc     namespace ns {
210f4a2713aSLionel Sambuc       struct Data {};
211f4a2713aSLionel Sambuc     }
212f4a2713aSLionel Sambuc 
operator <<(std::ostream & out,ns::Data data)213f4a2713aSLionel Sambuc     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'}}
214f4a2713aSLionel Sambuc       return out << "Some data";
215f4a2713aSLionel Sambuc     }
216f4a2713aSLionel Sambuc 
Use()217f4a2713aSLionel Sambuc     void Use() {
218f4a2713aSLionel Sambuc       Dump(ns::Data()); // expected-note {{here}}
219f4a2713aSLionel Sambuc     }
220f4a2713aSLionel Sambuc   }
221f4a2713aSLionel Sambuc 
222f4a2713aSLionel Sambuc   namespace my_file2_a {
223f4a2713aSLionel Sambuc     template<typename T>
Dump(const T & value)224f4a2713aSLionel Sambuc     void Dump(const T &value) {
225f4a2713aSLionel Sambuc       print(std::cout, value); // expected-error 4{{neither visible in the template definition nor found by argument-dependent lookup}}
226f4a2713aSLionel Sambuc     }
227f4a2713aSLionel Sambuc 
228f4a2713aSLionel Sambuc     namespace ns {
229f4a2713aSLionel Sambuc       struct Data {};
230f4a2713aSLionel Sambuc     }
231f4a2713aSLionel Sambuc     namespace ns2 {
232f4a2713aSLionel Sambuc       struct Data {};
233f4a2713aSLionel Sambuc     }
234f4a2713aSLionel Sambuc 
235*0a6a1f1dSLionel Sambuc     std::ostream &print(std::ostream &out, int); // expected-note-re {{should be declared prior to the call site{{$}}}}
236f4a2713aSLionel Sambuc     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'}}
237f4a2713aSLionel Sambuc     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'}}
238f4a2713aSLionel Sambuc     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}}
239f4a2713aSLionel Sambuc 
Use()240f4a2713aSLionel Sambuc     void Use() {
241f4a2713aSLionel Sambuc       Dump(0); // expected-note {{requested here}}
242f4a2713aSLionel Sambuc       Dump(ns::Data()); // expected-note {{requested here}}
243f4a2713aSLionel Sambuc       Dump(std::vector<ns2::Data>()); // expected-note {{requested here}}
244f4a2713aSLionel Sambuc       Dump(std::pair<ns::Data, ns2::Data>()); // expected-note {{requested here}}
245f4a2713aSLionel Sambuc     }
246f4a2713aSLionel Sambuc   }
247f4a2713aSLionel Sambuc 
248f4a2713aSLionel Sambuc   namespace unary {
249f4a2713aSLionel Sambuc     template<typename T>
Negate(const T & value)250f4a2713aSLionel Sambuc     T Negate(const T& value) {
251f4a2713aSLionel Sambuc       return !value; // expected-error {{call to function 'operator!' that is neither visible in the template definition nor found by argument-dependent lookup}}
252f4a2713aSLionel Sambuc     }
253f4a2713aSLionel Sambuc 
254f4a2713aSLionel Sambuc     namespace ns {
255f4a2713aSLionel Sambuc       struct Data {};
256f4a2713aSLionel Sambuc     }
257f4a2713aSLionel Sambuc 
258f4a2713aSLionel Sambuc     ns::Data operator!(ns::Data); // expected-note {{should be declared prior to the call site or in namespace 'PR10053::unary::ns'}}
259f4a2713aSLionel Sambuc 
Use()260f4a2713aSLionel Sambuc     void Use() {
261f4a2713aSLionel Sambuc       Negate(ns::Data()); // expected-note {{requested here}}
262f4a2713aSLionel Sambuc     }
263f4a2713aSLionel Sambuc   }
264f4a2713aSLionel Sambuc }
265f4a2713aSLionel Sambuc 
266f4a2713aSLionel Sambuc namespace PR10187 {
267f4a2713aSLionel Sambuc   namespace A1 {
268f4a2713aSLionel Sambuc     template<typename T>
269f4a2713aSLionel Sambuc     struct S {
fPR10187::A1::S270f4a2713aSLionel Sambuc       void f() {
271f4a2713aSLionel Sambuc         for (auto &a : e)
272f4a2713aSLionel Sambuc           __range(a); // expected-error {{undeclared identifier '__range'}}
273f4a2713aSLionel Sambuc       }
274f4a2713aSLionel Sambuc       int e[10];
275f4a2713aSLionel Sambuc     };
g()276f4a2713aSLionel Sambuc     void g() {
277f4a2713aSLionel Sambuc       S<int>().f(); // expected-note {{here}}
278f4a2713aSLionel Sambuc     }
279f4a2713aSLionel Sambuc   }
280f4a2713aSLionel Sambuc 
281f4a2713aSLionel Sambuc   namespace A2 {
282f4a2713aSLionel Sambuc     template<typename T>
283f4a2713aSLionel Sambuc     struct S {
fPR10187::A2::S284f4a2713aSLionel Sambuc       void f() {
285f4a2713aSLionel Sambuc         for (auto &a : e)
286f4a2713aSLionel Sambuc           __range(a); // expected-error {{undeclared identifier '__range'}}
287f4a2713aSLionel Sambuc       }
288f4a2713aSLionel Sambuc       T e[10];
289f4a2713aSLionel Sambuc     };
g()290f4a2713aSLionel Sambuc     void g() {
291f4a2713aSLionel Sambuc       S<int>().f(); // expected-note {{here}}
292f4a2713aSLionel Sambuc     }
293f4a2713aSLionel Sambuc     struct X {};
294f4a2713aSLionel Sambuc     void __range(X);
h()295f4a2713aSLionel Sambuc     void h() {
296f4a2713aSLionel Sambuc       S<X>().f();
297f4a2713aSLionel Sambuc     }
298f4a2713aSLionel Sambuc   }
299f4a2713aSLionel Sambuc 
300f4a2713aSLionel Sambuc   namespace B {
301f4a2713aSLionel Sambuc     template<typename T> void g(); // expected-note {{not viable}}
f()302f4a2713aSLionel Sambuc     template<typename T> void f() {
303f4a2713aSLionel Sambuc       g<int>(T()); // expected-error {{no matching function}}
304f4a2713aSLionel Sambuc     }
305f4a2713aSLionel Sambuc 
306f4a2713aSLionel Sambuc     namespace {
307f4a2713aSLionel Sambuc       struct S {};
308f4a2713aSLionel Sambuc     }
309f4a2713aSLionel Sambuc     void g(S);
310f4a2713aSLionel Sambuc 
311f4a2713aSLionel Sambuc     template void f<S>(); // expected-note {{here}}
312f4a2713aSLionel Sambuc   }
313f4a2713aSLionel Sambuc }
314f4a2713aSLionel Sambuc 
315f4a2713aSLionel Sambuc namespace rdar11242625 {
316f4a2713aSLionel Sambuc 
317f4a2713aSLionel Sambuc template <typename T>
318f4a2713aSLionel Sambuc struct Main {
319f4a2713aSLionel Sambuc   struct default_names {
320f4a2713aSLionel Sambuc     typedef int id;
321f4a2713aSLionel Sambuc   };
322f4a2713aSLionel Sambuc 
323f4a2713aSLionel Sambuc   template <typename T2 = typename default_names::id>
324f4a2713aSLionel Sambuc   struct TS {
325f4a2713aSLionel Sambuc     T2 q;
326f4a2713aSLionel Sambuc   };
327f4a2713aSLionel Sambuc };
328f4a2713aSLionel Sambuc 
329f4a2713aSLionel Sambuc struct Sub : public Main<int> {
330f4a2713aSLionel Sambuc   TS<> ff;
331f4a2713aSLionel Sambuc };
332f4a2713aSLionel Sambuc 
333f4a2713aSLionel Sambuc int arr[sizeof(Sub)];
334f4a2713aSLionel Sambuc 
335f4a2713aSLionel Sambuc }
336f4a2713aSLionel Sambuc 
337f4a2713aSLionel Sambuc namespace PR11421 {
338f4a2713aSLionel Sambuc template < unsigned > struct X {
339f4a2713aSLionel Sambuc   static const unsigned dimension = 3;
340f4a2713aSLionel Sambuc   template<unsigned dim=dimension>
341f4a2713aSLionel Sambuc   struct Y: Y<dim> { }; // expected-error{{circular inheritance between 'Y<dim>' and 'Y<dim>'}}
342f4a2713aSLionel Sambuc };
343f4a2713aSLionel Sambuc typedef X<3> X3;
344f4a2713aSLionel Sambuc X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
345f4a2713aSLionel Sambuc }
346f4a2713aSLionel Sambuc 
347f4a2713aSLionel Sambuc namespace rdar12629723 {
348f4a2713aSLionel Sambuc   template<class T>
349f4a2713aSLionel Sambuc   struct X {
350f4a2713aSLionel Sambuc     struct C : public C { }; // expected-error{{circular inheritance between 'rdar12629723::X::C' and 'rdar12629723::X::C'}}
351f4a2713aSLionel Sambuc 
352f4a2713aSLionel Sambuc     struct B;
353f4a2713aSLionel Sambuc 
354f4a2713aSLionel Sambuc     struct A : public B {  // expected-note{{'rdar12629723::X::A' declared here}}
foordar12629723::X::A355f4a2713aSLionel Sambuc       virtual void foo() { }
356f4a2713aSLionel Sambuc     };
357f4a2713aSLionel Sambuc 
358f4a2713aSLionel Sambuc     struct D : T::foo { };
359f4a2713aSLionel Sambuc     struct E : D { };
360f4a2713aSLionel Sambuc   };
361f4a2713aSLionel Sambuc 
362f4a2713aSLionel Sambuc   template<class T>
363f4a2713aSLionel Sambuc   struct X<T>::B : public A {  // expected-error{{circular inheritance between 'rdar12629723::X::A' and 'rdar12629723::X::B'}}
foordar12629723::X::B364f4a2713aSLionel Sambuc     virtual void foo() { }
365f4a2713aSLionel Sambuc   };
366f4a2713aSLionel Sambuc }
367f4a2713aSLionel Sambuc 
368f4a2713aSLionel Sambuc namespace test_reserved_identifiers {
tempf(A a,B b)369f4a2713aSLionel Sambuc   template<typename A, typename B> void tempf(A a, B b) {
370f4a2713aSLionel Sambuc     a + b;  // expected-error{{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}}
371f4a2713aSLionel Sambuc   }
372f4a2713aSLionel Sambuc   namespace __gnu_cxx { struct X {}; }
373f4a2713aSLionel Sambuc   namespace ns { struct Y {}; }
374f4a2713aSLionel Sambuc   void operator+(__gnu_cxx::X, ns::Y);  // expected-note{{or in namespace 'test_reserved_identifiers::ns'}}
test()375f4a2713aSLionel Sambuc   void test() {
376f4a2713aSLionel Sambuc     __gnu_cxx::X x;
377f4a2713aSLionel Sambuc     ns::Y y;
378f4a2713aSLionel Sambuc     tempf(x, y);  // expected-note{{in instantiation of}}
379f4a2713aSLionel Sambuc   }
380f4a2713aSLionel Sambuc }
381f4a2713aSLionel Sambuc 
382f4a2713aSLionel Sambuc // This test must live in the global namespace.
383f4a2713aSLionel Sambuc struct PR14695_X {};
384f4a2713aSLionel Sambuc // FIXME: This note is bogus; it is the using directive which would need to move
385f4a2713aSLionel Sambuc // to prior to the call site to fix the problem.
386f4a2713aSLionel Sambuc 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}}
PR14695_g(T t)387f4a2713aSLionel Sambuc 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}}
388f4a2713aSLionel Sambuc using namespace PR14695_A;
389f4a2713aSLionel Sambuc template void PR14695_g(PR14695_X); // expected-note{{requested here}}
390f4a2713aSLionel Sambuc 
391f4a2713aSLionel Sambuc namespace OperatorNew {
f(T t)392f4a2713aSLionel Sambuc   template<typename T> void f(T t) {
393f4a2713aSLionel Sambuc     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}}
394f4a2713aSLionel Sambuc     // FIXME: This should give the same error.
395f4a2713aSLionel Sambuc     new (t) int;
396f4a2713aSLionel Sambuc   }
397f4a2713aSLionel Sambuc   struct X {};
398f4a2713aSLionel Sambuc };
399f4a2713aSLionel Sambuc using size_t = decltype(sizeof(0));
400*0a6a1f1dSLionel Sambuc void *operator new(size_t, OperatorNew::X); // expected-note-re {{should be declared prior to the call site{{$}}}}
401f4a2713aSLionel Sambuc template void OperatorNew::f(OperatorNew::X); // expected-note {{instantiation of}}
402*0a6a1f1dSLionel Sambuc 
403*0a6a1f1dSLionel Sambuc namespace PR19936 {
T()404*0a6a1f1dSLionel Sambuc   template<typename T> decltype(*T()) f() {} // expected-note {{previous}}
T()405*0a6a1f1dSLionel Sambuc   template<typename T> decltype(T() * T()) g() {} // expected-note {{previous}}
406*0a6a1f1dSLionel Sambuc 
407*0a6a1f1dSLionel Sambuc   // Create some overloaded operators so we build an overload operator call
408*0a6a1f1dSLionel Sambuc   // instead of a builtin operator call for the dependent expression.
409*0a6a1f1dSLionel Sambuc   enum E {};
410*0a6a1f1dSLionel Sambuc   int operator*(E);
411*0a6a1f1dSLionel Sambuc   int operator*(E, E);
412*0a6a1f1dSLionel Sambuc 
413*0a6a1f1dSLionel Sambuc   // Check that they still profile the same.
T()414*0a6a1f1dSLionel Sambuc   template<typename T> decltype(*T()) f() {} // expected-error {{redefinition}}
T()415*0a6a1f1dSLionel Sambuc   template<typename T> decltype(T() * T()) g() {} // expected-error {{redefinition}}
416*0a6a1f1dSLionel Sambuc }
417