xref: /minix3/external/bsd/llvm/dist/clang/test/CXX/over/over.over/p2-resolve-single-template-id.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -Wno-bool-conversion %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc typedef __typeof__(((int*)0)-((int*)0)) ptrdiff_t;
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc namespace DontResolveTooEarly_WaitForOverloadResolution
6*f4a2713aSLionel Sambuc {
7*f4a2713aSLionel Sambuc   template <class T> T* f(int);	// #1
8*f4a2713aSLionel Sambuc   template <class T, class U> T& f(U); // #2
9*f4a2713aSLionel Sambuc 
g()10*f4a2713aSLionel Sambuc   void g() {
11*f4a2713aSLionel Sambuc     int *ip = f<int>(1);	// calls #1
12*f4a2713aSLionel Sambuc   }
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc   template <class T>
15*f4a2713aSLionel Sambuc     T* f2(int);
16*f4a2713aSLionel Sambuc   template <class T, class U>
17*f4a2713aSLionel Sambuc     T& f2(U);
18*f4a2713aSLionel Sambuc 
g2()19*f4a2713aSLionel Sambuc   void g2() {
20*f4a2713aSLionel Sambuc     int*ip = (f2<int>)(1); // ok
21*f4a2713aSLionel Sambuc   }
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc } // End namespace
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc namespace DontAllowUnresolvedOverloadedExpressionInAnUnusedExpression
26*f4a2713aSLionel Sambuc {
one()27*f4a2713aSLionel Sambuc   void one() { }
oneT()28*f4a2713aSLionel Sambuc   template<class T> void oneT() { }
29*f4a2713aSLionel Sambuc 
two()30*f4a2713aSLionel Sambuc   void two() { } // expected-note 2 {{possible target for call}}
two(int)31*f4a2713aSLionel Sambuc   void two(int) { } // expected-note 2 {{possible target for call}}
twoT()32*f4a2713aSLionel Sambuc   template<class T> void twoT() { }  // expected-note 2 {{possible target for call}}
twoT(T)33*f4a2713aSLionel Sambuc   template<class T> void twoT(T) { }  // expected-note 2 {{possible target for call}}
34*f4a2713aSLionel Sambuc 
check()35*f4a2713aSLionel Sambuc   void check()
36*f4a2713aSLionel Sambuc   {
37*f4a2713aSLionel Sambuc     one; // expected-warning {{expression result unused}}
38*f4a2713aSLionel Sambuc     two; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
39*f4a2713aSLionel Sambuc     oneT<int>; // expected-warning {{expression result unused}}
40*f4a2713aSLionel Sambuc     twoT<int>; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
41*f4a2713aSLionel Sambuc   }
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc   // check the template function case
check()44*f4a2713aSLionel Sambuc   template<class T> void check()
45*f4a2713aSLionel Sambuc   {
46*f4a2713aSLionel Sambuc     one; // expected-warning {{expression result unused}}
47*f4a2713aSLionel Sambuc     two; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
48*f4a2713aSLionel Sambuc     oneT<int>; // expected-warning {{expression result unused}}
49*f4a2713aSLionel Sambuc     twoT<int>; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
50*f4a2713aSLionel Sambuc 
51*f4a2713aSLionel Sambuc   }
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc }
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc   template<typename T>
twoT()56*f4a2713aSLionel Sambuc     void twoT() { }
57*f4a2713aSLionel Sambuc   template<typename T, typename U>
twoT(T)58*f4a2713aSLionel Sambuc     void twoT(T) { }
59*f4a2713aSLionel Sambuc 
60*f4a2713aSLionel Sambuc 
two()61*f4a2713aSLionel Sambuc   void two() { }; //expected-note 5{{candidate}}
two(int)62*f4a2713aSLionel Sambuc   void two(int) { }; //expected-note 5{{candidate}}
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc 
one()66*f4a2713aSLionel Sambuc   void one() { }
67*f4a2713aSLionel Sambuc   template<class T>
oneT()68*f4a2713aSLionel Sambuc     void oneT() { }
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc   template<class T>
cant_resolve()71*f4a2713aSLionel Sambuc   void cant_resolve() { } //expected-note 3{{candidate}}
72*f4a2713aSLionel Sambuc 
cant_resolve(T)73*f4a2713aSLionel Sambuc   template<class T> void cant_resolve(T) { }//expected-note 3{{candidate}}
74*f4a2713aSLionel Sambuc 
75*f4a2713aSLionel Sambuc 
main()76*f4a2713aSLionel Sambuc int main()
77*f4a2713aSLionel Sambuc {
78*f4a2713aSLionel Sambuc 
79*f4a2713aSLionel Sambuc   { static_cast<void>(one); }
80*f4a2713aSLionel Sambuc   { (void)(one); }
81*f4a2713aSLionel Sambuc   { static_cast<void>(oneT<int>); }
82*f4a2713aSLionel Sambuc   { (void)(oneT<int>); }
83*f4a2713aSLionel Sambuc 
84*f4a2713aSLionel Sambuc   { static_cast<void>(two); } // expected-error {{address of overloaded function 'two' cannot be static_cast to type 'void'}}
85*f4a2713aSLionel Sambuc   { (void)(two); } // expected-error {{address of overloaded function 'two' cannot be cast to type 'void'}}
86*f4a2713aSLionel Sambuc   { static_cast<void>(twoT<int>); }
87*f4a2713aSLionel Sambuc   { (void)(twoT<int>); }
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc 
90*f4a2713aSLionel Sambuc   { ptrdiff_t x = reinterpret_cast<ptrdiff_t>(oneT<int>); }
91*f4a2713aSLionel Sambuc   { (void) reinterpret_cast<int (*)(char, double)>(oneT<int>); }
92*f4a2713aSLionel Sambuc   { (void) reinterpret_cast<ptrdiff_t>(one); }
93*f4a2713aSLionel Sambuc   { (void) reinterpret_cast<int (*)(char, double)>(one); }
94*f4a2713aSLionel Sambuc 
95*f4a2713aSLionel Sambuc   { ptrdiff_t x = reinterpret_cast<ptrdiff_t>(twoT<int>); }
96*f4a2713aSLionel Sambuc   { (void) reinterpret_cast<int (*)(char, double)>(twoT<int>); }
97*f4a2713aSLionel Sambuc   { (void) reinterpret_cast<void (*)(int)>(two); } //expected-error {{reinterpret_cast}}
98*f4a2713aSLionel Sambuc   { (void) static_cast<void (*)(int)>(two); } //ok
99*f4a2713aSLionel Sambuc 
100*f4a2713aSLionel Sambuc   { (void) reinterpret_cast<int>(two); } //expected-error {{reinterpret_cast}}
101*f4a2713aSLionel Sambuc   { (void) reinterpret_cast<int (*)(char, double)>(two); } //expected-error {{reinterpret_cast}}
102*f4a2713aSLionel Sambuc 
103*f4a2713aSLionel Sambuc   { bool b = (twoT<int>); }
104*f4a2713aSLionel Sambuc   { bool b = (twoT<int, int>); }
105*f4a2713aSLionel Sambuc 
106*f4a2713aSLionel Sambuc   { bool b = &twoT<int>; //&foo<int>; }
107*f4a2713aSLionel Sambuc     b = &(twoT<int>); }
108*f4a2713aSLionel Sambuc 
109*f4a2713aSLionel Sambuc   { ptrdiff_t x = (ptrdiff_t) &twoT<int>;
110*f4a2713aSLionel Sambuc       x = (ptrdiff_t) &twoT<int>; }
111*f4a2713aSLionel Sambuc 
112*f4a2713aSLionel Sambuc   { ptrdiff_t x = (ptrdiff_t) twoT<int>;
113*f4a2713aSLionel Sambuc       x = (ptrdiff_t) twoT<int>; }
114*f4a2713aSLionel Sambuc 
115*f4a2713aSLionel Sambuc 
116*f4a2713aSLionel Sambuc   { ptrdiff_t x = (ptrdiff_t) &twoT<int,int>;
117*f4a2713aSLionel Sambuc   x = (ptrdiff_t) &twoT<int>; }
118*f4a2713aSLionel Sambuc 
119*f4a2713aSLionel Sambuc   { oneT<int>;   &oneT<int>; } //expected-warning 2{{expression result unused}}
120*f4a2713aSLionel Sambuc   { static_cast<void>(cant_resolve<int>); } // expected-error {{address of overload}}
121*f4a2713aSLionel Sambuc   { bool b = cant_resolve<int>; } // expected-error {{address of overload}}
122*f4a2713aSLionel Sambuc   { (void) cant_resolve<int>; } // expected-error {{address of overload}}
123*f4a2713aSLionel Sambuc 
124*f4a2713aSLionel Sambuc }
125*f4a2713aSLionel Sambuc 
126*f4a2713aSLionel Sambuc namespace member_pointers {
127*f4a2713aSLionel Sambuc   struct S {
fmember_pointers::S128*f4a2713aSLionel Sambuc     template <typename T> bool f(T) { return false; } // expected-note 4 {{possible target for call}}
gmember_pointers::S129*f4a2713aSLionel Sambuc     template <typename T> static bool g(T) { return false; }
130*f4a2713aSLionel Sambuc 
hmember_pointers::S131*f4a2713aSLionel Sambuc     template <typename T> bool h(T) { return false; }  // expected-note 3 {{possible target for call}}
hmember_pointers::S132*f4a2713aSLionel Sambuc     template <int N> static bool h(int) { return false; } // expected-note 3 {{possible target for call}}
133*f4a2713aSLionel Sambuc   };
134*f4a2713aSLionel Sambuc 
test(S s)135*f4a2713aSLionel Sambuc   void test(S s) {
136*f4a2713aSLionel Sambuc     if (S::f<char>) return; // expected-error {{call to non-static member function without an object argument}}
137*f4a2713aSLionel Sambuc     if (S::f<int>) return; // expected-error {{call to non-static member function without an object argument}}
138*f4a2713aSLionel Sambuc     if (&S::f<char>) return;
139*f4a2713aSLionel Sambuc     if (&S::f<int>) return;
140*f4a2713aSLionel Sambuc     if (s.f<char>) return; // expected-error {{reference to non-static member function must be called}}
141*f4a2713aSLionel Sambuc     if (s.f<int>) return; // expected-error {{reference to non-static member function must be called}}
142*f4a2713aSLionel Sambuc     if (&s.f<char>) return; // expected-error {{cannot create a non-constant pointer to member function}}
143*f4a2713aSLionel Sambuc     if (&s.f<int>) return; // expected-error {{cannot create a non-constant pointer to member function}}
144*f4a2713aSLionel Sambuc 
145*f4a2713aSLionel Sambuc     if (S::g<char>) return;
146*f4a2713aSLionel Sambuc     if (S::g<int>) return;
147*f4a2713aSLionel Sambuc     if (&S::g<char>) return;
148*f4a2713aSLionel Sambuc     if (&S::g<int>) return;
149*f4a2713aSLionel Sambuc     if (s.g<char>) return;
150*f4a2713aSLionel Sambuc     if (s.g<int>) return;
151*f4a2713aSLionel Sambuc     if (&s.g<char>) return;
152*f4a2713aSLionel Sambuc     if (&s.g<int>) return;
153*f4a2713aSLionel Sambuc 
154*f4a2713aSLionel Sambuc     if (S::h<42>) return;
155*f4a2713aSLionel Sambuc     if (S::h<int>) return; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
156*f4a2713aSLionel Sambuc     if (&S::h<42>) return;
157*f4a2713aSLionel Sambuc     if (&S::h<int>) return;
158*f4a2713aSLionel Sambuc     if (s.h<42>) return;
159*f4a2713aSLionel Sambuc     if (s.h<int>) return; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
160*f4a2713aSLionel Sambuc     if (&s.h<42>) return;
161*f4a2713aSLionel Sambuc     if (&s.h<int>) return; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
162*f4a2713aSLionel Sambuc 
163*f4a2713aSLionel Sambuc     { bool b = S::f<char>; } // expected-error {{call to non-static member function without an object argument}}
164*f4a2713aSLionel Sambuc     { bool b = S::f<int>; } // expected-error {{call to non-static member function without an object argument}}
165*f4a2713aSLionel Sambuc     { bool b = &S::f<char>; }
166*f4a2713aSLionel Sambuc     { bool b = &S::f<int>; }
167*f4a2713aSLionel Sambuc     // These next two errors are terrible.
168*f4a2713aSLionel Sambuc     { bool b = s.f<char>; } // expected-error {{reference to non-static member function must be called}}
169*f4a2713aSLionel Sambuc     { bool b = s.f<int>; } // expected-error {{reference to non-static member function must be called}}
170*f4a2713aSLionel Sambuc     { bool b = &s.f<char>; } // expected-error {{cannot create a non-constant pointer to member function}}
171*f4a2713aSLionel Sambuc     { bool b = &s.f<int>; } // expected-error {{cannot create a non-constant pointer to member function}}
172*f4a2713aSLionel Sambuc 
173*f4a2713aSLionel Sambuc     { bool b = S::g<char>; }
174*f4a2713aSLionel Sambuc     { bool b = S::g<int>; }
175*f4a2713aSLionel Sambuc     { bool b = &S::g<char>; }
176*f4a2713aSLionel Sambuc     { bool b = &S::g<int>; }
177*f4a2713aSLionel Sambuc     { bool b = s.g<char>; }
178*f4a2713aSLionel Sambuc     { bool b = s.g<int>; }
179*f4a2713aSLionel Sambuc     { bool b = &s.g<char>; }
180*f4a2713aSLionel Sambuc     { bool b = &s.g<int>; }
181*f4a2713aSLionel Sambuc 
182*f4a2713aSLionel Sambuc     { bool b = S::h<42>; }
183*f4a2713aSLionel Sambuc     { bool b = S::h<int>; } // expected-error {{can't form member pointer of type 'bool' without '&' and class name}}
184*f4a2713aSLionel Sambuc     { bool b = &S::h<42>; }
185*f4a2713aSLionel Sambuc     { bool b = &S::h<int>; }
186*f4a2713aSLionel Sambuc     { bool b = s.h<42>; }
187*f4a2713aSLionel Sambuc     { bool b = s.h<int>; } // expected-error {{can't form member pointer of type 'bool' without '&' and class name}}
188*f4a2713aSLionel Sambuc     { bool b = &s.h<42>; }
189*f4a2713aSLionel Sambuc     { bool b = &s.h<int>; } // expected-error {{can't form member pointer of type 'bool' without '&' and class name}}
190*f4a2713aSLionel Sambuc   }
191*f4a2713aSLionel Sambuc }
192