blob: 8c119ec8c6de819314e1ec32ff8a9be4474e32a4 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor3384c9c2009-05-19 00:01:19 +00002
3
4struct Sub0 {
5 int &operator[](int);
6};
7
8struct Sub1 {
Sebastian Redlf322ed62009-10-29 20:17:01 +00009 long &operator[](long); // expected-note{{candidate function}}
Douglas Gregor3384c9c2009-05-19 00:01:19 +000010};
11
12struct ConvertibleToInt {
13 operator int();
14};
15
16template<typename T, typename U, typename Result>
17struct Subscript0 {
18 void test(T t, U u) {
John McCall1eb3e102010-01-07 02:04:15 +000019 Result &result = t[u]; // expected-error{{no viable overloaded operator[] for type}}
Douglas Gregor3384c9c2009-05-19 00:01:19 +000020 }
21};
22
23template struct Subscript0<int*, int, int&>;
24template struct Subscript0<Sub0, int, int&>;
25template struct Subscript0<Sub1, ConvertibleToInt, long&>;
26template struct Subscript0<Sub1, Sub0, long&>; // expected-note{{instantiation}}
Sebastian Redlf322ed62009-10-29 20:17:01 +000027
28// PR5345
29template <typename T>
30struct S {
31 bool operator[](int n) const { return true; }
32};
33
34template <typename T>
35void Foo(const S<int>& s, T x) {
36 if (s[0]) {}
37}
38
39void Bar() {
40 Foo(S<int>(), 0);
41}