211 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2// RUN: cp %s %t3// RUN: not %clang_cc1 -fixit %t -x c++ -DFIXIT4// RUN: %clang_cc1 -fsyntax-only %t -x c++ -DFIXIT5// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace6 7void test1() {8 int a[] = {0,1,1,2,3};9 int []b = {0,1,4,9,16};10 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}11 // CHECK: {{^}} int []b = {0,1,4,9,16};12 // CHECK: {{^}} ~~ ^13 // CHECK: {{^}} []14 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:9}:""15 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:10-[[@LINE-6]]:10}:"[]"16 17 int c = a[0];18 int d = b[0]; // No undeclared identifier error here.19 20 int *e = a;21 int *f = b; // No undeclared identifier error here.22 23 int[1] g[2];24 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}25 // CHECK: {{^}} int[1] g[2];26 // CHECK: {{^}} ~~~ ^27 // CHECK: {{^}} [1]28 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:6-[[@LINE-5]]:9}:""29 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:14-[[@LINE-6]]:14}:"[1]"30}31 32void test2() {33 int [3] (*a) = 0;34 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}35 // CHECK: {{^}} int [3] (*a) = 0;36 // CHECK: {{^}} ~~~ ^37 // CHECK: {{^}} [3]38 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""39 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:15-[[@LINE-6]]:15}:"[3]"40 41#ifndef FIXIT42 // Make sure a is corrected to be like type y, instead of like type z.43 int (*b)[3] = a;44 int (*c[3]) = a; // expected-error{{}}45#endif46}47 48struct A {49 static int [1][1]x;50 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}51 // CHECK: {{^}} static int [1][1]x;52 // CHECK: {{^}} ~~~~~~ ^53 // CHECK: {{^}} [1][1]54 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:14-[[@LINE-5]]:20}:""55 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:21-[[@LINE-6]]:21}:"[1][1]"56};57 58int [1][1]A::x = { {42} };59// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}60// CHECK: {{^}}int [1][1]A::x = { {42} };61// CHECK: {{^}} ~~~~~~ ^62// CHECK: {{^}} [1][1]63// CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:11}:""64// CHECK: fix-it:{{.*}}:{[[@LINE-6]]:15-[[@LINE-6]]:15}:"[1][1]"65 66struct B { static int (*x)[5]; };67int [5] *B::x = 0;68// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}69// CHECK: {{^}}int [5] *B::x = 0;70// CHECK: {{^}} ~~~ ^71// CHECK: {{^}} ( )[5]72// CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:9}:""73// CHECK: fix-it:{{.*}}:{[[@LINE-6]]:9-[[@LINE-6]]:9}:"("74// CHECK: fix-it:{{.*}}:{[[@LINE-7]]:14-[[@LINE-7]]:14}:")[5]"75 76void test3() {77 int [3] *a;78 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}79 // CHECK: {{^}} int [3] *a;80 // CHECK: {{^}} ~~~ ^81 // CHECK: {{^}} ( )[3]82 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""83 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("84 // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:13-[[@LINE-7]]:13}:")[3]"85 86 int (*b)[3] = a; // no error87}88 89void test4() {90 int [2] a;91 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}92 // CHECK: {{^}} int [2] a;93 // CHECK: {{^}} ~~~ ^94 // CHECK: {{^}} [2]95 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""96 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:12-[[@LINE-6]]:12}:"[2]"97 98 int [2] &b = a;99 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}100 // CHECK: {{^}} int [2] &b = a;101 // CHECK: {{^}} ~~~ ^102 // CHECK: {{^}} ( )[2]103 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""104 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("105 // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:13-[[@LINE-7]]:13}:")[2]"106 107}108 109namespace test5 {110#ifndef FIXIT111int [][][];112// expected-error@-1{{expected unqualified-id}}113// CHECK: {{^}}int [][][];114// CHECK: {{^}} ^115 116struct C {117 int [];118 // expected-error@-1{{expected member name or ';' after declaration specifiers}}119 // CHECK: {{^}} int [];120 // CHECK: {{^}} ~~~ ^121};122 123#endif124}125 126namespace test6 {127struct A {128 static int arr[3];129};130int [3] ::test6::A::arr = {1,2,3};131// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}132// CHECK: {{^}}int [3] ::test6::A::arr = {1,2,3};133// CHECK: {{^}} ~~~ ^134// CHECK: {{^}} [3]135// CHECK: fix-it:{{.*}}:{[[@LINE-5]]:5-[[@LINE-5]]:9}:""136// CHECK: fix-it:{{.*}}:{[[@LINE-6]]:24-[[@LINE-6]]:24}:"[3]"137 138}139 140namespace test7 {141class A{};142void test() {143 int [3] A::*a;144 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}145 // CHECK: {{^}} int [3] A::*a;146 // CHECK: {{^}} ~~~ ^147 // CHECK: {{^}} ( )[3]148 // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""149 // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("150 // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:16-[[@LINE-7]]:16}:")[3]"151}152}153 154namespace test8 {155struct A {156 static const char f[];157};158const char[] A::f = "f";159// expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}160}161 162namespace gh147333 {163 template<class T, char fmt>164 constexpr inline auto& to_print_fmt = "";165 template<> constexpr inline char[] to_print_fmt<unsigned, 'x'> = "0x%x";166 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}167 168#ifndef FIXIT169 // Further related test cases.170 171 int[1] operator+();172 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}173 // expected-error@-2{{function cannot return array type}}174 175 int[1] operator ""_x(unsigned long long);176 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}177 // expected-error@-2{{function cannot return array type}}178 179 struct A {180 int[1] operator int();181 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}182 // TODO: The following is too noisy and redundant.183 // expected-error@-3{{conversion function cannot have a return type}}184 // expected-error@-4{{cannot specify any part of a return type in the declaration of a conversion function}}185 // expected-error@-5{{conversion function cannot convert to an array type}}186 187 int[1] A();188 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}189 // TODO: The following is too noisy and redundant.190 // expected-error@-3{{function cannot return array type}}191 // expected-error@-4{{constructor cannot have a return type}}192 193 int[1] ~A();194 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}195 // TODO: This isn't helpful.196 // expected-error@-3{{array has incomplete element type 'void'}}197 };198 199 template<typename T>200 struct B {201 int[1] B<T>();202 // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the name}}203 // TODO: The following is too noisy and redundant.204 // expected-error@-3{{function cannot return array type}}205 // expected-error@-4{{constructor cannot have a return type}}206 };207#endif208}209 210// CHECK: 32 errors generated.211