Douglas Gregor | 3384c9c | 2009-05-19 00:01:19 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
| 2 | |
| 3 | |
| 4 | struct Sub0 { |
| 5 | int &operator[](int); |
| 6 | }; |
| 7 | |
| 8 | struct Sub1 { |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9 | long &operator[](long); // expected-note{{candidate function}} |
Douglas Gregor | 3384c9c | 2009-05-19 00:01:19 +0000 | [diff] [blame] | 10 | }; |
| 11 | |
| 12 | struct ConvertibleToInt { |
| 13 | operator int(); |
| 14 | }; |
| 15 | |
| 16 | template<typename T, typename U, typename Result> |
| 17 | struct Subscript0 { |
| 18 | void test(T t, U u) { |
| 19 | Result &result = t[u]; // expected-error{{subscripted value is not}} |
| 20 | } |
| 21 | }; |
| 22 | |
| 23 | template struct Subscript0<int*, int, int&>; |
| 24 | template struct Subscript0<Sub0, int, int&>; |
| 25 | template struct Subscript0<Sub1, ConvertibleToInt, long&>; |
| 26 | template struct Subscript0<Sub1, Sub0, long&>; // expected-note{{instantiation}} |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 27 | |
| 28 | // PR5345 |
| 29 | template <typename T> |
| 30 | struct S { |
| 31 | bool operator[](int n) const { return true; } |
| 32 | }; |
| 33 | |
| 34 | template <typename T> |
| 35 | void Foo(const S<int>& s, T x) { |
| 36 | if (s[0]) {} |
| 37 | } |
| 38 | |
| 39 | void Bar() { |
| 40 | Foo(S<int>(), 0); |
| 41 | } |