1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc struct Sub0 {
5*f4a2713aSLionel Sambuc int &operator[](int);
6*f4a2713aSLionel Sambuc };
7*f4a2713aSLionel Sambuc
8*f4a2713aSLionel Sambuc struct Sub1 {
9*f4a2713aSLionel Sambuc long &operator[](long); // expected-note{{candidate function}}
10*f4a2713aSLionel Sambuc };
11*f4a2713aSLionel Sambuc
12*f4a2713aSLionel Sambuc struct ConvertibleToInt {
13*f4a2713aSLionel Sambuc operator int();
14*f4a2713aSLionel Sambuc };
15*f4a2713aSLionel Sambuc
16*f4a2713aSLionel Sambuc template<typename T, typename U, typename Result>
17*f4a2713aSLionel Sambuc struct Subscript0 {
testSubscript018*f4a2713aSLionel Sambuc void test(T t, U u) {
19*f4a2713aSLionel Sambuc Result &result = t[u]; // expected-error{{no viable overloaded operator[] for type}}
20*f4a2713aSLionel Sambuc }
21*f4a2713aSLionel Sambuc };
22*f4a2713aSLionel Sambuc
23*f4a2713aSLionel Sambuc template struct Subscript0<int*, int, int&>;
24*f4a2713aSLionel Sambuc template struct Subscript0<Sub0, int, int&>;
25*f4a2713aSLionel Sambuc template struct Subscript0<Sub1, ConvertibleToInt, long&>;
26*f4a2713aSLionel Sambuc template struct Subscript0<Sub1, Sub0, long&>; // expected-note{{instantiation}}
27*f4a2713aSLionel Sambuc
28*f4a2713aSLionel Sambuc // PR5345
29*f4a2713aSLionel Sambuc template <typename T>
30*f4a2713aSLionel Sambuc struct S {
operator []S31*f4a2713aSLionel Sambuc bool operator[](int n) const { return true; }
32*f4a2713aSLionel Sambuc };
33*f4a2713aSLionel Sambuc
34*f4a2713aSLionel Sambuc template <typename T>
Foo(const S<int> & s,T x)35*f4a2713aSLionel Sambuc void Foo(const S<int>& s, T x) {
36*f4a2713aSLionel Sambuc if (s[0]) {}
37*f4a2713aSLionel Sambuc }
38*f4a2713aSLionel Sambuc
Bar()39*f4a2713aSLionel Sambuc void Bar() {
40*f4a2713aSLionel Sambuc Foo(S<int>(), 0);
41*f4a2713aSLionel Sambuc }
42