Douglas Gregor | 717a2bf | 2010-11-08 03:58:01 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | void g(); |
| 3 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 4 | void f(); // expected-note 11{{candidate function}} |
| 5 | void f(int); // expected-note 11{{candidate function}} |
Douglas Gregor | 717a2bf | 2010-11-08 03:58:01 +0000 | [diff] [blame] | 6 | |
Larisse Voufo | 4384712 | 2013-07-19 23:00:19 +0000 | [diff] [blame] | 7 | template <class T> |
Richard Smith | 72a36a1 | 2013-08-14 00:00:44 +0000 | [diff] [blame] | 8 | void t(T); // expected-note 3{{candidate function}} \ |
Larisse Voufo | 4384712 | 2013-07-19 23:00:19 +0000 | [diff] [blame] | 9 | // expected-note 3{{candidate template ignored: could not match 'void' against 'int'}} |
| 10 | template <class T> |
Richard Smith | 72a36a1 | 2013-08-14 00:00:44 +0000 | [diff] [blame] | 11 | void t(T *); // expected-note 3{{candidate function}} \ |
Larisse Voufo | 4384712 | 2013-07-19 23:00:19 +0000 | [diff] [blame] | 12 | // expected-note 3{{candidate template ignored: could not match 'void' against 'int'}} |
Douglas Gregor | 717a2bf | 2010-11-08 03:58:01 +0000 | [diff] [blame] | 13 | |
| 14 | template<class T> void u(T); |
| 15 | |
| 16 | int main() |
| 17 | { |
| 18 | { bool b = (void (&)(char))f; } // expected-error{{does not match required type}} |
| 19 | { bool b = (void (*)(char))f; } // expected-error{{does not match required type}} |
| 20 | |
| 21 | { bool b = (void (&)(int))f; } //ok |
| 22 | { bool b = (void (*)(int))f; } //ok |
| 23 | |
| 24 | { bool b = static_cast<void (&)(char)>(f); } // expected-error{{does not match}} |
| 25 | { bool b = static_cast<void (*)(char)>(f); } // expected-error{{address of overloaded function}} |
| 26 | |
| 27 | { bool b = static_cast<void (&)(int)>(f); } //ok |
| 28 | { bool b = static_cast<void (*)(int)>(f); } //ok |
| 29 | |
| 30 | |
| 31 | { bool b = reinterpret_cast<void (&)(char)>(f); } // expected-error{{cannot resolve}} |
| 32 | { bool b = reinterpret_cast<void (*)(char)>(f); } // expected-error{{cannot resolve}} |
| 33 | |
| 34 | { bool b = reinterpret_cast<void (*)(char)>(g); } //ok |
| 35 | { bool b = static_cast<void (*)(char)>(g); } // expected-error{{not allowed}} |
| 36 | |
| 37 | { bool b = reinterpret_cast<void (&)(int)>(f); } // expected-error{{cannot resolve}} |
| 38 | { bool b = reinterpret_cast<void (*)(int)>(f); } // expected-error{{cannot resolve}} |
| 39 | |
| 40 | { bool b = (int (&)(char))t; } // expected-error{{does not match}} |
| 41 | { bool b = (int (*)(char))t; } // expected-error{{does not match}} |
| 42 | |
| 43 | { bool b = (void (&)(int))t; } //ok |
| 44 | { bool b = (void (*)(int))t; } //ok |
| 45 | |
| 46 | { bool b = static_cast<void (&)(char)>(t); } //ok |
| 47 | { bool b = static_cast<void (*)(char)>(t); } //ok |
| 48 | |
| 49 | { bool b = static_cast<void (&)(int)>(t); } //ok |
| 50 | { bool b = static_cast<void (*)(int)>(t); } //ok |
| 51 | |
| 52 | |
| 53 | { bool b = reinterpret_cast<void (&)(char)>(t); } // expected-error{{cannot resolve}} |
| 54 | { bool b = reinterpret_cast<void (*)(char)>(t); } // expected-error{{cannot resolve}} |
| 55 | |
| 56 | { bool b = reinterpret_cast<int (*)(char)>(g); } //ok |
| 57 | { bool b = static_cast<int (*)(char)>(t); } // expected-error{{cannot be static_cast}} |
| 58 | { bool b = static_cast<int (&)(char)>(t); } // expected-error{{does not match required}} |
| 59 | |
| 60 | { bool b = static_cast<void (&)(char)>(f); } // expected-error{{does not match}} |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 61 | |
| 62 | { |
| 63 | // The error should be reported when casting overloaded function to the |
| 64 | // compatible function type (not to be confused with function pointer or |
| 65 | // function reference type.) |
| 66 | typedef void (FnType)(int); |
| 67 | FnType a = static_cast<FnType>(f); // expected-error{{address of overloaded function}} |
| 68 | FnType b = (FnType)(f); // expected-error{{address of overloaded function}} |
| 69 | } |
Douglas Gregor | 717a2bf | 2010-11-08 03:58:01 +0000 | [diff] [blame] | 70 | } |