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