David Blaikie | 282ad87 | 2012-10-16 18:53:14 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -verify %s -std=c++11 |
Fariborz Jahanian | b3c44f9 | 2009-10-01 20:39:51 +0000 | [diff] [blame] | 2 | |
| 3 | struct R { |
| 4 | R(int); |
| 5 | }; |
| 6 | |
| 7 | struct A { |
| 8 | A(R); |
| 9 | }; |
| 10 | |
Sebastian Redl | 22653ba | 2011-08-30 19:58:05 +0000 | [diff] [blame] | 11 | struct B { // expected-note 3 {{candidate constructor (the implicit copy constructor) not viable}} \ |
| 12 | expected-note 3 {{candidate constructor (the implicit move constructor) not viable}} |
John McCall | 909acf8 | 2011-02-14 18:34:10 +0000 | [diff] [blame] | 13 | B(A); // expected-note 3 {{candidate constructor not viable}} |
Fariborz Jahanian | b3c44f9 | 2009-10-01 20:39:51 +0000 | [diff] [blame] | 14 | }; |
| 15 | |
| 16 | int main () { |
John McCall | 909acf8 | 2011-02-14 18:34:10 +0000 | [diff] [blame] | 17 | B(10); // expected-error {{no matching conversion for functional-style cast from 'int' to 'B'}} |
| 18 | (B)10; // expected-error {{no matching conversion for C-style cast from 'int' to 'B'}} |
Eli Friedman | 3fd26b8 | 2013-07-26 23:47:47 +0000 | [diff] [blame] | 19 | static_cast<B>(10); // expected-error {{no matching conversion for static_cast from 'int' to 'B'}} |
Fariborz Jahanian | b3c44f9 | 2009-10-01 20:39:51 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Douglas Gregor | ad8b222 | 2009-11-06 01:14:41 +0000 | [diff] [blame] | 22 | template<class T> |
| 23 | struct X0 { |
| 24 | X0(const T &); |
| 25 | }; |
| 26 | |
| 27 | template<class T> |
| 28 | X0<T> make_X0(const T &Val) { |
| 29 | return X0<T>(Val); |
| 30 | } |
| 31 | |
| 32 | void test_X0() { |
Douglas Gregor | e656562 | 2010-02-09 07:26:29 +0000 | [diff] [blame] | 33 | const char array[2] = { 'a', 'b' }; |
Douglas Gregor | ad8b222 | 2009-11-06 01:14:41 +0000 | [diff] [blame] | 34 | make_X0(array); |
| 35 | } |
Douglas Gregor | f4f2ff7 | 2009-11-06 05:48:00 +0000 | [diff] [blame] | 36 | |
| 37 | // PR5210 recovery |
| 38 | class C { |
| 39 | protected: |
| 40 | template <int> float* &f0(); // expected-note{{candidate}} |
| 41 | template <unsigned> float* &f0(); // expected-note{{candidate}} |
| 42 | |
| 43 | void f1() { |
| 44 | static_cast<float*>(f0<0>()); // expected-error{{ambiguous}} |
| 45 | } |
| 46 | }; |
David Blaikie | 282ad87 | 2012-10-16 18:53:14 +0000 | [diff] [blame] | 47 | |
| 48 | void *intToPointer1(short s) { |
| 49 | return (void*)s; // expected-warning{{cast to 'void *' from smaller integer type 'short'}} |
| 50 | } |
| 51 | |
| 52 | void *intToPointer2(short s) { |
| 53 | return reinterpret_cast<void*>(s); |
| 54 | } |
| 55 | |
| 56 | void *intToPointer3(bool b) { |
| 57 | return (void*)b; |
| 58 | } |
| 59 | |
| 60 | void *intToPointer4() { |
| 61 | return (void*)(3 + 7); |
| 62 | } |
| 63 | |
| 64 | void *intToPointer5(long l) { |
| 65 | return (void*)l; |
| 66 | } |
Eli Friedman | 61a511f | 2013-06-20 01:35:13 +0000 | [diff] [blame] | 67 | |
| 68 | struct AmbiguousCast { |
| 69 | operator int(); // expected-note {{candidate function}} |
| 70 | operator unsigned int(); // expected-note {{candidate function}} |
| 71 | }; |
| 72 | long long AmbiguousCastFunc(AmbiguousCast& a) { |
| 73 | return static_cast<long long>(a); // expected-error {{ambiguous conversion for static_cast from 'AmbiguousCast' to 'long long'}} |
| 74 | } |
Eli Friedman | 3fd26b8 | 2013-07-26 23:47:47 +0000 | [diff] [blame] | 75 | |
| 76 | namespace PR16680 { |
| 77 | void f(int (*__pf)()); |
| 78 | int g() { |
| 79 | f(reinterpret_cast<int>(0.0f)); // expected-error {{reinterpret_cast from 'float' to 'int' is not allowed}} |
| 80 | } |
| 81 | } |