Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | f1991ea | 2008-11-07 22:36:19 +0000 | [diff] [blame] | 2 | struct X { |
| 3 | operator bool(); |
| 4 | }; |
| 5 | |
| 6 | int& f(bool); |
| 7 | float& f(int); |
| 8 | |
| 9 | void f_test(X x) { |
| 10 | int& i1 = f(x); |
| 11 | } |
| 12 | |
| 13 | struct Y { |
| 14 | operator short(); |
| 15 | operator float(); |
| 16 | }; |
| 17 | |
| 18 | void g(int); |
| 19 | |
| 20 | void g_test(Y y) { |
| 21 | g(y); |
Douglas Gregor | cb9b977 | 2008-11-10 16:14:15 +0000 | [diff] [blame] | 22 | short s; |
| 23 | s = y; |
| 24 | } |
| 25 | |
| 26 | struct A { }; |
| 27 | struct B : A { }; |
| 28 | |
| 29 | struct C { |
| 30 | operator B&(); |
| 31 | }; |
| 32 | |
| 33 | // Test reference binding via an lvalue conversion function. |
| 34 | void h(volatile A&); |
| 35 | void h_test(C c) { |
| 36 | h(c); |
Douglas Gregor | f1991ea | 2008-11-07 22:36:19 +0000 | [diff] [blame] | 37 | } |
Douglas Gregor | 734d986 | 2009-01-30 23:27:23 +0000 | [diff] [blame] | 38 | |
| 39 | // Test conversion followed by copy-construction |
| 40 | struct FunkyDerived; |
| 41 | |
| 42 | struct Base { |
| 43 | Base(const FunkyDerived&); |
| 44 | }; |
| 45 | |
| 46 | struct Derived : Base { }; |
| 47 | |
| 48 | struct FunkyDerived : Base { }; |
| 49 | |
| 50 | struct ConvertibleToBase { |
| 51 | operator Base(); |
| 52 | }; |
| 53 | |
| 54 | struct ConvertibleToDerived { |
| 55 | operator Derived(); |
| 56 | }; |
| 57 | |
| 58 | struct ConvertibleToFunkyDerived { |
| 59 | operator FunkyDerived(); |
| 60 | }; |
| 61 | |
| 62 | void test_conversion(ConvertibleToBase ctb, ConvertibleToDerived ctd, |
| 63 | ConvertibleToFunkyDerived ctfd) { |
| 64 | Base b1 = ctb; |
| 65 | Base b2(ctb); |
| 66 | Base b3 = ctd; |
| 67 | Base b4(ctd); |
Douglas Gregor | 2b1e003 | 2009-02-02 22:11:10 +0000 | [diff] [blame] | 68 | Base b5 = ctfd; |
Douglas Gregor | 734d986 | 2009-01-30 23:27:23 +0000 | [diff] [blame] | 69 | } |