instantiate-subscript.cpp 844 B

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