[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaTemplate / instantiate-subscript.cpp
blobcb20f2dd721f7f75fa9753bb6f7bf0bac2df9eef
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++23 %s
4 struct Sub0 {
5 int &operator[](int);
6 };
8 struct Sub1 {
9 long &operator[](long); // expected-note{{candidate function}}
12 struct ConvertibleToInt {
13 operator int();
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{{no viable overloaded operator[] for type}}
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}}
28 // PR5345
29 template <typename T>
30 struct S {
31 bool operator[](int n) const { return true; }
34 template <typename T>
35 void Foo(const S<int>& s, T x) {
36 if (s[0]) {}
39 void Bar() {
40 Foo(S<int>(), 0);