// RUN: %clang_cc1 -fsyntax-only -verify -Wno-bool-conversion %s typedef __typeof__(((int*)0)-((int*)0)) ptrdiff_t; namespace DontResolveTooEarly_WaitForOverloadResolution { template T* f(int); // #1 template T& f(U); // #2 void g() { int *ip = f(1); // calls #1 } template T* f2(int); template T& f2(U); void g2() { int*ip = (f2)(1); // ok } } // End namespace namespace DontAllowUnresolvedOverloadedExpressionInAnUnusedExpression { void one() { } template void oneT() { } void two() { } // expected-note 2 {{possible target for call}} void two(int) { } // expected-note 2 {{possible target for call}} template void twoT() { } // expected-note 2 {{possible target for call}} template void twoT(T) { } // expected-note 2 {{possible target for call}} void check() { one; // expected-warning {{expression result unused}} two; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} oneT; // expected-warning {{expression result unused}} twoT; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} } // check the template function case template void check() { one; // expected-warning {{expression result unused}} two; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} oneT; // expected-warning {{expression result unused}} twoT; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} } } template void twoT() { } template void twoT(T) { } void two() { }; //expected-note 5{{candidate}} void two(int) { }; //expected-note 5{{candidate}} void one() { } template void oneT() { } template void cant_resolve() { } //expected-note 3{{candidate}} template void cant_resolve(T) { }//expected-note 3{{candidate}} int main() { { static_cast(one); } { (void)(one); } { static_cast(oneT); } { (void)(oneT); } { static_cast(two); } // expected-error {{address of overloaded function 'two' cannot be static_cast to type 'void'}} { (void)(two); } // expected-error {{address of overloaded function 'two' cannot be cast to type 'void'}} { static_cast(twoT); } { (void)(twoT); } { ptrdiff_t x = reinterpret_cast(oneT); } { (void) reinterpret_cast(oneT); } { (void) reinterpret_cast(one); } { (void) reinterpret_cast(one); } { ptrdiff_t x = reinterpret_cast(twoT); } { (void) reinterpret_cast(twoT); } { (void) reinterpret_cast(two); } //expected-error {{reinterpret_cast}} { (void) static_cast(two); } //ok { (void) reinterpret_cast(two); } //expected-error {{reinterpret_cast}} { (void) reinterpret_cast(two); } //expected-error {{reinterpret_cast}} { bool b = (twoT); } { bool b = (twoT); } { bool b = &twoT; //&foo; } b = &(twoT); } { ptrdiff_t x = (ptrdiff_t) &twoT; x = (ptrdiff_t) &twoT; } { ptrdiff_t x = (ptrdiff_t) twoT; x = (ptrdiff_t) twoT; } { ptrdiff_t x = (ptrdiff_t) &twoT; x = (ptrdiff_t) &twoT; } { oneT; &oneT; } //expected-warning 2{{expression result unused}} { static_cast(cant_resolve); } // expected-error {{address of overload}} { bool b = cant_resolve; } // expected-error {{address of overload}} { (void) cant_resolve; } // expected-error {{address of overload}} } namespace member_pointers { struct S { template bool f(T) { return false; } // expected-note 4 {{possible target for call}} template static bool g(T) { return false; } template bool h(T) { return false; } // expected-note 3 {{possible target for call}} template static bool h(int) { return false; } // expected-note 3 {{possible target for call}} }; void test(S s) { if (S::f) return; // expected-error {{call to non-static member function without an object argument}} if (S::f) return; // expected-error {{call to non-static member function without an object argument}} if (&S::f) return; if (&S::f) return; if (s.f) return; // expected-error {{reference to non-static member function must be called}} if (s.f) return; // expected-error {{reference to non-static member function must be called}} if (&s.f) return; // expected-error {{cannot create a non-constant pointer to member function}} if (&s.f) return; // expected-error {{cannot create a non-constant pointer to member function}} if (S::g) return; if (S::g) return; if (&S::g) return; if (&S::g) return; if (s.g) return; if (s.g) return; if (&s.g) return; if (&s.g) return; if (S::h<42>) return; if (S::h) return; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} if (&S::h<42>) return; if (&S::h) return; if (s.h<42>) return; if (s.h) return; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} if (&s.h<42>) return; if (&s.h) return; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} { bool b = S::f; } // expected-error {{call to non-static member function without an object argument}} { bool b = S::f; } // expected-error {{call to non-static member function without an object argument}} { bool b = &S::f; } { bool b = &S::f; } // These next two errors are terrible. { bool b = s.f; } // expected-error {{reference to non-static member function must be called}} { bool b = s.f; } // expected-error {{reference to non-static member function must be called}} { bool b = &s.f; } // expected-error {{cannot create a non-constant pointer to member function}} { bool b = &s.f; } // expected-error {{cannot create a non-constant pointer to member function}} { bool b = S::g; } { bool b = S::g; } { bool b = &S::g; } { bool b = &S::g; } { bool b = s.g; } { bool b = s.g; } { bool b = &s.g; } { bool b = &s.g; } { bool b = S::h<42>; } { bool b = S::h; } // expected-error {{can't form member pointer of type 'bool' without '&' and class name}} { bool b = &S::h<42>; } { bool b = &S::h; } { bool b = s.h<42>; } { bool b = s.h; } // expected-error {{can't form member pointer of type 'bool' without '&' and class name}} { bool b = &s.h<42>; } { bool b = &s.h; } // expected-error {{can't form member pointer of type 'bool' without '&' and class name}} } }