1717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor// RUN: %clang_cc1 -fsyntax-only -verify %s 2717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregorvoid g(); 3717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 46bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid f(); // expected-note 11{{candidate function}} 56bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid f(int); // expected-note 11{{candidate function}} 6717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 74384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufotemplate <class T> 872a36a14b10c18bc72bf0472dc29e86327615c26Richard Smithvoid t(T); // expected-note 3{{candidate function}} \ 94384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo // expected-note 3{{candidate template ignored: could not match 'void' against 'int'}} 104384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufotemplate <class T> 1172a36a14b10c18bc72bf0472dc29e86327615c26Richard Smithvoid t(T *); // expected-note 3{{candidate function}} \ 124384712b3a0aedd7c68d6abdb0407850f7b46c8bLarisse Voufo // expected-note 3{{candidate template ignored: could not match 'void' against 'int'}} 13717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 14717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregortemplate<class T> void u(T); 15717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 16717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregorint main() 17717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor{ 18717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = (void (&)(char))f; } // expected-error{{does not match required type}} 19717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = (void (*)(char))f; } // expected-error{{does not match required type}} 20717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 21717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = (void (&)(int))f; } //ok 22717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = (void (*)(int))f; } //ok 23717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 24717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<void (&)(char)>(f); } // expected-error{{does not match}} 25717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<void (*)(char)>(f); } // expected-error{{address of overloaded function}} 26717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 27717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<void (&)(int)>(f); } //ok 28717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<void (*)(int)>(f); } //ok 29717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 30717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 31717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = reinterpret_cast<void (&)(char)>(f); } // expected-error{{cannot resolve}} 32717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = reinterpret_cast<void (*)(char)>(f); } // expected-error{{cannot resolve}} 33717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 34717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = reinterpret_cast<void (*)(char)>(g); } //ok 35717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<void (*)(char)>(g); } // expected-error{{not allowed}} 36717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 37717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = reinterpret_cast<void (&)(int)>(f); } // expected-error{{cannot resolve}} 38717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = reinterpret_cast<void (*)(int)>(f); } // expected-error{{cannot resolve}} 39717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 40717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = (int (&)(char))t; } // expected-error{{does not match}} 41717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = (int (*)(char))t; } // expected-error{{does not match}} 42717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 43717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = (void (&)(int))t; } //ok 44717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = (void (*)(int))t; } //ok 45717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 46717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<void (&)(char)>(t); } //ok 47717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<void (*)(char)>(t); } //ok 48717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 49717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<void (&)(int)>(t); } //ok 50717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<void (*)(int)>(t); } //ok 51717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 52717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 53717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = reinterpret_cast<void (&)(char)>(t); } // expected-error{{cannot resolve}} 54717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = reinterpret_cast<void (*)(char)>(t); } // expected-error{{cannot resolve}} 55717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 56717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = reinterpret_cast<int (*)(char)>(g); } //ok 57717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<int (*)(char)>(t); } // expected-error{{cannot be static_cast}} 58717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<int (&)(char)>(t); } // expected-error{{does not match required}} 59717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor 60717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor { bool b = static_cast<void (&)(char)>(f); } // expected-error{{does not match}} 616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines { 636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // The error should be reported when casting overloaded function to the 646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // compatible function type (not to be confused with function pointer or 656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // function reference type.) 666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines typedef void (FnType)(int); 676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines FnType a = static_cast<FnType>(f); // expected-error{{address of overloaded function}} 686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines FnType b = (FnType)(f); // expected-error{{address of overloaded function}} 696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines } 70717a2bf760ef1daf74f839eb3c9ad73ad2aa6d60Douglas Gregor} 71