| 1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
| 2 | // RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s |
| 3 | namespace std { |
| 4 | template <class X> |
| 5 | class initializer_list { |
| 6 | public: |
| 7 | initializer_list(); |
| 8 | }; |
| 9 | } |
| 10 | |
| 11 | class Foo { |
| 12 | public: |
| 13 | Foo(); |
| 14 | Foo(std::initializer_list<int>); |
| 15 | bool operator==(const Foo); |
| 16 | Foo operator+(const Foo); |
| 17 | }; |
| 18 | |
| 19 | #define EQ(x,y) (void)(x == y) // expected-note 6{{defined here}} |
| 20 | void test_EQ() { |
| 21 | Foo F; |
| 22 | F = Foo{1,2}; |
| 23 | |
| 24 | EQ(F,F); |
| 25 | EQ(F,Foo()); |
| 26 | EQ(F,Foo({1,2,3})); |
| 27 | EQ(Foo({1,2,3}),F); |
| 28 | EQ((Foo{1,2,3}),(Foo{1,2,3})); |
| 29 | EQ(F, F + F); |
| 30 | EQ(F, Foo({1,2,3}) + Foo({1,2,3})); |
| 31 | EQ(F, (Foo{1,2,3} + Foo{1,2,3})); |
| 32 | |
| 33 | EQ(F,Foo{1,2,3}); |
| 34 | // expected-error@-1 {{too many arguments provided}} |
| 35 | // expected-note@-2 {{parentheses are required}} |
| 36 | EQ(Foo{1,2,3},F); |
| 37 | // expected-error@-1 {{too many arguments provided}} |
| 38 | // expected-note@-2 {{parentheses are required}} |
| 39 | EQ(Foo{1,2,3},Foo{1,2,3}); |
| 40 | // expected-error@-1 {{too many arguments provided}} |
| 41 | // expected-note@-2 {{parentheses are required}} |
| 42 | |
| 43 | EQ(Foo{1,2,3} + Foo{1,2,3}, F); |
| 44 | // expected-error@-1 {{too many arguments provided}} |
| 45 | // expected-note@-2 {{parentheses are required}} |
| 46 | EQ(F, Foo({1,2,3}) + Foo{1,2,3}); |
| 47 | // expected-error@-1 {{too many arguments provided}} |
| 48 | // expected-note@-2 {{parentheses are required}} |
| 49 | EQ(F, Foo{1,2,3} + Foo{1,2,3}); |
| 50 | // expected-error@-1 {{too many arguments provided}} |
| 51 | // expected-note@-2 {{parentheses are required}} |
| 52 | } |
| 53 | |
| 54 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{33:8-33:8}:"(" |
| 55 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{33:18-33:18}:")" |
| 56 | |
| 57 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{36:6-36:6}:"(" |
| 58 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{36:16-36:16}:")" |
| 59 | |
| 60 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{39:6-39:6}:"(" |
| 61 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{39:16-39:16}:")" |
| 62 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{39:17-39:17}:"(" |
| 63 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{39:27-39:27}:")" |
| 64 | |
| 65 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{43:6-43:6}:"(" |
| 66 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{43:29-43:29}:")" |
| 67 | |
| 68 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{46:9-46:9}:"(" |
| 69 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{46:34-46:34}:")" |
| 70 | |
| 71 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{49:9-49:9}:"(" |
| 72 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{49:32-49:32}:")" |
| 73 | |
| 74 | #define NE(x,y) (void)(x != y) // expected-note 6{{defined here}} |
| 75 | // Operator != isn't defined. This tests that the corrected macro arguments |
| 76 | // are used in the macro expansion. |
| 77 | void test_NE() { |
| 78 | Foo F; |
| 79 | |
| 80 | NE(F,F); |
| 81 | // expected-error@-1 {{invalid operands}} |
| 82 | NE(F,Foo()); |
| 83 | // expected-error@-1 {{invalid operands}} |
| 84 | NE(F,Foo({1,2,3})); |
| 85 | // expected-error@-1 {{invalid operands}} |
| 86 | NE((Foo{1,2,3}),(Foo{1,2,3})); |
| 87 | // expected-error@-1 {{invalid operands}} |
| 88 | |
| 89 | NE(F,Foo{1,2,3}); |
| 90 | // expected-error@-1 {{too many arguments provided}} |
| 91 | // expected-note@-2 {{parentheses are required}} |
| 92 | // expected-error@-3 {{invalid operands}} |
| 93 | NE(Foo{1,2,3},F); |
| 94 | // expected-error@-1 {{too many arguments provided}} |
| 95 | // expected-note@-2 {{parentheses are required}} |
| 96 | // expected-error@-3 {{invalid operands}} |
| 97 | NE(Foo{1,2,3},Foo{1,2,3}); |
| 98 | // expected-error@-1 {{too many arguments provided}} |
| 99 | // expected-note@-2 {{parentheses are required}} |
| 100 | // expected-error@-3 {{invalid operands}} |
| 101 | |
| 102 | NE(Foo{1,2,3} + Foo{1,2,3}, F); |
| 103 | // expected-error@-1 {{too many arguments provided}} |
| 104 | // expected-note@-2 {{parentheses are required}} |
| 105 | // expected-error@-3 {{invalid operands}} |
| 106 | NE(F, Foo({1,2,3}) + Foo{1,2,3}); |
| 107 | // expected-error@-1 {{too many arguments provided}} |
| 108 | // expected-note@-2 {{parentheses are required}} |
| 109 | // expected-error@-3 {{invalid operands}} |
| 110 | NE(F, Foo{1,2,3} + Foo{1,2,3}); |
| 111 | // expected-error@-1 {{too many arguments provided}} |
| 112 | // expected-note@-2 {{parentheses are required}} |
| 113 | // expected-error@-3 {{invalid operands}} |
| 114 | } |
| 115 | |
| 116 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{89:8-89:8}:"(" |
| 117 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{89:18-89:18}:")" |
| 118 | |
| 119 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{93:6-93:6}:"(" |
| 120 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{93:16-93:16}:")" |
| 121 | |
| 122 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{97:6-97:6}:"(" |
| 123 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{97:16-97:16}:")" |
| 124 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{97:17-97:17}:"(" |
| 125 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{97:27-97:27}:")" |
| 126 | |
| 127 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{102:6-102:6}:"(" |
| 128 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{102:29-102:29}:")" |
| 129 | |
| 130 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{106:9-106:9}:"(" |
| 131 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{106:34-106:34}:")" |
| 132 | |
| 133 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{110:9-110:9}:"(" |
| 134 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{110:32-110:32}:")" |
| 135 | |
| 136 | #define INIT(var, init) Foo var = init; // expected-note 3{{defined here}} |
| 137 | // Can't use an initializer list as a macro argument. The commas in the list |
| 138 | // will be interpretted as argument separaters and adding parenthesis will |
| 139 | // make it no longer an initializer list. |
| 140 | void test() { |
| 141 | INIT(a, Foo()); |
| 142 | INIT(b, Foo({1, 2, 3})); |
| 143 | INIT(c, Foo()); |
| 144 | |
| 145 | INIT(d, Foo{1, 2, 3}); |
| 146 | // expected-error@-1 {{too many arguments provided}} |
| 147 | // expected-note@-2 {{parentheses are required}} |
| 148 | |
| 149 | // Can't be fixed by parentheses. |
| 150 | INIT(e, {1, 2, 3}); |
| 151 | // expected-error@-1 {{too many arguments provided}} |
| 152 | // expected-error@-2 {{use of undeclared identifier}} |
| 153 | // expected-note@-3 {{cannot use initializer list at the beginning of a macro argument}} |
| 154 | |
| 155 | // Can't be fixed by parentheses. |
| 156 | INIT(e, {1, 2, 3} + {1, 2, 3}); |
| 157 | // expected-error@-1 {{too many arguments provided}} |
| 158 | // expected-error@-2 {{use of undeclared identifier}} |
| 159 | // expected-note@-3 {{cannot use initializer list at the beginning of a macro argument}} |
| 160 | } |
| 161 | |
| 162 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{145:11-145:11}:"(" |
| 163 | // CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{145:23-145:23}:")" |
| 164 | |
| 165 | #define M(name,a,b,c,d,e,f,g,h,i,j,k,l) \ |
| 166 | Foo name = a + b + c + d + e + f + g + h + i + j + k + l; |
| 167 | // expected-note@-2 2{{defined here}} |
| 168 | void test2() { |
| 169 | M(F1, Foo(), Foo(), Foo(), Foo(), Foo(), Foo(), |
| 170 | Foo(), Foo(), Foo(), Foo(), Foo(), Foo()); |
| 171 | |
| 172 | M(F2, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, |
| 173 | Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}); |
| 174 | // expected-error@-2 {{too many arguments provided}} |
| 175 | // expected-note@-3 {{parentheses are required}} |
| 176 | |
| 177 | M(F3, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}, |
| 178 | {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}); |
| 179 | // expected-error@-2 {{too many arguments provided}} |
| 180 | // expected-error@-3 {{use of undeclared identifier}} |
| 181 | // expected-note@-4 {{cannot use initializer list at the beginning of a macro argument}} |
| 182 | } |
| 183 | |