summaryrefslogtreecommitdiff
path: root/test/Parser/brackets.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Parser/brackets.c')
-rw-r--r--test/Parser/brackets.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/Parser/brackets.c b/test/Parser/brackets.c
new file mode 100644
index 000000000000..2750d0e42ed8
--- /dev/null
+++ b/test/Parser/brackets.c
@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: cp %s %t
+// RUN: not %clang_cc1 -fixit %t -x c -DFIXIT
+// RUN: %clang_cc1 -fsyntax-only %t -x c -DFIXIT
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
+
+void test1() {
+ int a[] = {0,1,1,2,3};
+ int []b = {0,1,4,9,16};
+ // expected-error@-1{{brackets go after the identifier}}
+ // CHECK: {{^}} int []b = {0,1,4,9,16};
+ // CHECK: {{^}} ~~ ^
+ // CHECK: {{^}} []
+ // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:9}:""
+ // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:10-[[@LINE-6]]:10}:"[]"
+
+ int c = a[0];
+ int d = b[0]; // No undeclared identifer error here.
+
+ int *e = a;
+ int *f = b; // No undeclared identifer error here.
+}
+
+struct S {
+ int [1][1]x;
+ // expected-error@-1{{brackets go after the identifier}}
+ // CHECK: {{^}} int [1][1]x;
+ // CHECK: {{^}} ~~~~~~ ^
+ // CHECK: {{^}} [1][1]
+ // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:13}:""
+ // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:14-[[@LINE-6]]:14}:"[1][1]"
+} s;
+
+#ifndef FIXIT
+void test2() {
+ int [][][];
+ // expected-error@-1{{expected identifier or '('}}
+ // CHECK: {{^}} int [][][];
+ // CHECK: {{^}} ^
+ // CHECK-NOT: fix-it
+ struct T {
+ int [];
+ // expected-error@-1{{expected member name or ';' after declaration specifiers}}
+ // CHECK: {{^}} int [];
+ // CHECK: {{^}} ~~~ ^
+ // CHECK-NOT: fix-it
+ };
+}
+
+void test3() {
+ int [5] *;
+ // expected-error@-1{{expected identifier or '('}}
+ // CHECK: {{^}} int [5] *;
+ // CHECK: {{^}} ^
+ // CHECK-NOT: fix-it
+ // expected-error@-5{{brackets go after the identifier}}
+ // CHECK: {{^}} int [5] *;
+ // CHECK: {{^}} ~~~~ ^
+ // CHECK: {{^}} ()[5]
+ // CHECK: fix-it:{{.*}}:{[[@LINE-9]]:7-[[@LINE-9]]:11}:""
+ // CHECK: fix-it:{{.*}}:{[[@LINE-10]]:11-[[@LINE-10]]:11}:"("
+ // CHECK: fix-it:{{.*}}:{[[@LINE-11]]:12-[[@LINE-11]]:12}:")[5]"
+
+ int [5] * a;
+ // expected-error@-1{{brackets go after the identifier}}
+ // CHECK: {{^}} int [5] * a;
+ // CHECK: {{^}} ~~~~ ^
+ // CHECK: {{^}} ( )[5]
+ // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
+ // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
+ // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:14-[[@LINE-7]]:14}:")[5]"
+
+ int *b[5] = a; // expected-error{{}} a should not be corrected to type b
+
+ int (*c)[5] = a; // a should be the same type as c
+}
+#endif
+
+// CHECK: 8 errors generated.