[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Parser / cxx2b-subscript.cpp
blobc56df48a379d9fab3f6af028b9bad00ab0cd174f
1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx2b -std=c++2b %s
2 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
4 //cxx2b-no-diagnostics
6 struct S {
7 constexpr int operator[](int i) {
8 return i;
10 constexpr int operator[](int a, int b) { // cxx20-error {{overloaded 'operator[]' cannot have more than one parameter before C++2b}}
11 return a + b;
13 constexpr int operator[]() { // cxx20-error {{overloaded 'operator[]' cannot have no parameter before C++2b}}
14 return 42;
18 struct Defaults {
19 constexpr int operator[](int i = 0) { // cxx20-error {{overloaded 'operator[]' cannot have a defaulted parameter before C++2b}}
20 return 0;
22 constexpr int operator[](int a, int b, int c = 0) { // cxx20-error {{overloaded 'operator[]' cannot have a defaulted parameter before C++2b}}\
23 // cxx20-error {{cannot have more than one parameter before C++2b}}
24 return 0;
28 template <typename... T>
29 struct T1 {
30 constexpr auto operator[](T &&...arg); // cxx20-error {{overloaded 'operator[]' cannot have no parameter before C++2b}} \
31 // cxx20-error {{overloaded 'operator[]' cannot have more than one parameter before C++2b}}
34 T1<> t10; // cxx20-note {{requested here}}
35 T1<int, int> t12; // cxx20-note {{requested here}}
36 T1<int> t11;
38 struct Variadic {
39 constexpr int operator[](auto &&...arg) { return 0; }
42 void f() {
43 S 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++2b}}
47 (void)S{}[]; // cxx20-error {{expected expression}}
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++2b}}
54 Variadic{}[]; // cxx20-error {{expected expression}}
55 Variadic{}[1];
56 Variadic{}[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++2b}}