Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Sebastian Redl | 8593c78 | 2009-05-21 11:50:50 +0000 | [diff] [blame] | 2 | struct A { |
| 3 | }; |
| 4 | |
| 5 | struct ConvertibleToA { |
| 6 | operator A(); |
| 7 | }; |
| 8 | |
| 9 | struct ConvertibleToConstA { |
| 10 | operator const A(); |
| 11 | }; |
| 12 | |
| 13 | struct B { |
Douglas Gregor | 3307475 | 2009-09-30 21:46:01 +0000 | [diff] [blame] | 14 | B& operator=(B&); // expected-note 4 {{candidate function}} |
Sebastian Redl | 8593c78 | 2009-05-21 11:50:50 +0000 | [diff] [blame] | 15 | }; |
| 16 | |
| 17 | struct ConvertibleToB { |
| 18 | operator B(); |
| 19 | }; |
| 20 | |
| 21 | struct ConvertibleToBref { |
| 22 | operator B&(); |
| 23 | }; |
| 24 | |
| 25 | struct ConvertibleToConstB { |
| 26 | operator const B(); |
| 27 | }; |
| 28 | |
| 29 | struct ConvertibleToConstBref { |
| 30 | operator const B&(); |
| 31 | }; |
| 32 | |
| 33 | struct C { |
| 34 | int operator=(int); // expected-note{{candidate function}} |
| 35 | long operator=(long); // expected-note{{candidate function}} |
| 36 | int operator+=(int); // expected-note{{candidate function}} |
| 37 | int operator+=(long); // expected-note{{candidate function}} |
| 38 | }; |
| 39 | |
| 40 | struct D { |
| 41 | D& operator+=(const D &); |
| 42 | }; |
| 43 | |
| 44 | struct ConvertibleToInt { |
| 45 | operator int(); |
| 46 | }; |
| 47 | |
| 48 | void test() { |
| 49 | A a, na; |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 50 | const A constA = A(); |
Sebastian Redl | 8593c78 | 2009-05-21 11:50:50 +0000 | [diff] [blame] | 51 | ConvertibleToA convertibleToA; |
| 52 | ConvertibleToConstA convertibleToConstA; |
| 53 | |
| 54 | B b, nb; |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 55 | const B constB = B(); |
Sebastian Redl | 8593c78 | 2009-05-21 11:50:50 +0000 | [diff] [blame] | 56 | ConvertibleToB convertibleToB; |
| 57 | ConvertibleToBref convertibleToBref; |
| 58 | ConvertibleToConstB convertibleToConstB; |
| 59 | ConvertibleToConstBref convertibleToConstBref; |
| 60 | |
| 61 | C c, nc; |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 62 | const C constC = C(); |
Sebastian Redl | 8593c78 | 2009-05-21 11:50:50 +0000 | [diff] [blame] | 63 | |
| 64 | D d, nd; |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 65 | const D constD = D(); |
Sebastian Redl | 8593c78 | 2009-05-21 11:50:50 +0000 | [diff] [blame] | 66 | |
| 67 | ConvertibleToInt convertibleToInt; |
| 68 | |
| 69 | na = a; |
| 70 | na = constA; |
| 71 | na = convertibleToA; |
| 72 | na = convertibleToConstA; |
| 73 | na += a; // expected-error{{no viable overloaded '+='}} |
| 74 | |
| 75 | nb = b; |
| 76 | nb = constB; // expected-error{{no viable overloaded '='}} |
| 77 | nb = convertibleToB; // expected-error{{no viable overloaded '='}} |
| 78 | nb = convertibleToBref; |
| 79 | nb = convertibleToConstB; // expected-error{{no viable overloaded '='}} |
| 80 | nb = convertibleToConstBref; // expected-error{{no viable overloaded '='}} |
| 81 | |
| 82 | nc = c; |
| 83 | nc = constC; |
| 84 | nc = 1; |
| 85 | nc = 1L; |
| 86 | nc = 1.0; // expected-error{{use of overloaded operator '=' is ambiguous}} |
| 87 | nc += 1; |
| 88 | nc += 1L; |
| 89 | nc += 1.0; // expected-error{{use of overloaded operator '+=' is ambiguous}} |
| 90 | |
| 91 | nd = d; |
| 92 | nd += d; |
| 93 | nd += constD; |
| 94 | |
| 95 | int i; |
| 96 | i = convertibleToInt; |
Douglas Gregor | d4eea83 | 2010-04-09 00:35:39 +0000 | [diff] [blame] | 97 | i = a; // expected-error{{assigning to 'int' from incompatible type 'A'}} |
Sebastian Redl | 8593c78 | 2009-05-21 11:50:50 +0000 | [diff] [blame] | 98 | } |
| 99 | |