brackets.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // RUN: cp %s %t
  3. // RUN: not %clang_cc1 -fixit %t -x c -DFIXIT
  4. // RUN: %clang_cc1 -fsyntax-only %t -x c -DFIXIT
  5. // RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
  6. void test1() {
  7. int a[] = {0,1,1,2,3};
  8. int []b = {0,1,4,9,16};
  9. // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the identifier}}
  10. // CHECK: {{^}} int []b = {0,1,4,9,16};
  11. // CHECK: {{^}} ~~ ^
  12. // CHECK: {{^}} []
  13. // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:9}:""
  14. // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:10-[[@LINE-6]]:10}:"[]"
  15. int c = a[0];
  16. int d = b[0]; // No undeclared identifer error here.
  17. int *e = a;
  18. int *f = b; // No undeclared identifer error here.
  19. }
  20. struct S {
  21. int [1][1]x;
  22. // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the identifier}}
  23. // CHECK: {{^}} int [1][1]x;
  24. // CHECK: {{^}} ~~~~~~ ^
  25. // CHECK: {{^}} [1][1]
  26. // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:13}:""
  27. // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:14-[[@LINE-6]]:14}:"[1][1]"
  28. } s;
  29. #ifndef FIXIT
  30. void test2() {
  31. int [][][];
  32. // expected-error@-1{{expected identifier or '('}}
  33. // CHECK: {{^}} int [][][];
  34. // CHECK: {{^}} ^
  35. // CHECK-NOT: fix-it
  36. struct T {
  37. int [];
  38. // expected-error@-1{{expected member name or ';' after declaration specifiers}}
  39. // CHECK: {{^}} int [];
  40. // CHECK: {{^}} ~~~ ^
  41. // CHECK-NOT: fix-it
  42. };
  43. }
  44. void test3() {
  45. int [5] *;
  46. // expected-error@-1{{expected identifier or '('}}
  47. // CHECK: {{^}} int [5] *;
  48. // CHECK: {{^}} ^
  49. // CHECK-NOT: fix-it
  50. // expected-error@-5{{brackets are not allowed here; to declare an array, place the brackets after the identifier}}
  51. // CHECK: {{^}} int [5] *;
  52. // CHECK: {{^}} ~~~~ ^
  53. // CHECK: {{^}} ()[5]
  54. // CHECK: fix-it:{{.*}}:{[[@LINE-9]]:7-[[@LINE-9]]:11}:""
  55. // CHECK: fix-it:{{.*}}:{[[@LINE-10]]:11-[[@LINE-10]]:11}:"("
  56. // CHECK: fix-it:{{.*}}:{[[@LINE-11]]:12-[[@LINE-11]]:12}:")[5]"
  57. int [5] * a;
  58. // expected-error@-1{{brackets are not allowed here; to declare an array, place the brackets after the identifier}}
  59. // CHECK: {{^}} int [5] * a;
  60. // CHECK: {{^}} ~~~~ ^
  61. // CHECK: {{^}} ( )[5]
  62. // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
  63. // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
  64. // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:14-[[@LINE-7]]:14}:")[5]"
  65. int *b[5] = a; // expected-error{{}} a should not be corrected to type b
  66. int (*c)[5] = a; // a should be the same type as c
  67. }
  68. #endif
  69. // CHECK: 8 errors generated.