llvm-project
58 строк · 2.3 Кб
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx23 -std=c++23 %s
2// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
3
4//cxx23-no-diagnostics
5
6struct S {7constexpr int operator[](int i) {8return i;9}10constexpr int operator[](int a, int b) { // cxx20-error {{overloaded 'operator[]' cannot have more than one parameter before C++23}}11return a + b;12}13constexpr int operator[]() { // cxx20-error {{overloaded 'operator[]' cannot have no parameter before C++23}}14return 42;15}16};17
18struct Defaults {19constexpr int operator[](int i = 0) { // cxx20-error {{overloaded 'operator[]' cannot have a defaulted parameter before C++23}}20return 0;21}22constexpr int operator[](int a, int b, int c = 0) { // cxx20-error {{overloaded 'operator[]' cannot have a defaulted parameter before C++23}}\23// cxx20-error {{cannot have more than one parameter before C++23}}
24return 0;25}26};27
28template <typename... T>29struct T1 {30constexpr auto operator[](T &&...arg); // cxx20-error {{overloaded 'operator[]' cannot have no parameter before C++23}} \31// cxx20-error {{overloaded 'operator[]' cannot have more than one parameter before C++23}}
32};33
34T1<> t10; // cxx20-note {{requested here}}35T1<int, int> t12; // cxx20-note {{requested here}}36T1<int> t11;37
38struct Variadic {39constexpr int operator[](auto &&...arg) { return 0; }40};41
42void f() {43S s;44(void)s[0];45(void)s[1, 2]; // cxx20-warning {{left operand of comma operator has no effect}}\46// cxx20-warning {{top-level comma expression in array subscript is deprecated in C++20 and unsupported in C++23}}
47(void)S{}[]; // cxx20-error {{expected expression}}48
49(void)Defaults{}[1];50(void)Defaults{}[]; // cxx20-error {{expected expression}}51(void)Defaults{}[1, 2]; // cxx20-warning {{left operand of comma operator has no effect}}\52// cxx20-warning {{top-level comma expression in array subscript is deprecated in C++20 and unsupported in C++23}}
53
54Variadic{}[]; // cxx20-error {{expected expression}}55Variadic{}[1];56Variadic{}[1, 2]; // cxx20-warning {{left operand of comma operator has no effect}}\57// cxx20-warning {{top-level comma expression in array subscript is deprecated in C++20 and unsupported in C++23}}
58}
59