Home | History | Annotate | Download | only in Parser
      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 
      7 void test1() {
      8   int a[] = {0,1,1,2,3};
      9   int []b = {0,1,4,9,16};
     10   // expected-error@-1{{brackets go after the identifier}}
     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 identifer error here.
     19 
     20   int *e = a;
     21   int *f = b; // No undeclared identifer error here.
     22 }
     23 
     24 struct S {
     25   int [1][1]x;
     26   // expected-error@-1{{brackets go after the identifier}}
     27   // CHECK: {{^}}  int [1][1]x;
     28   // CHECK: {{^}}      ~~~~~~ ^
     29   // CHECK: {{^}}             [1][1]
     30   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:13}:""
     31   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:14-[[@LINE-6]]:14}:"[1][1]"
     32 } s;
     33 
     34 #ifndef FIXIT
     35 void test2() {
     36   int [][][];
     37   // expected-error@-1{{expected identifier or '('}}
     38   // CHECK: {{^}}  int [][][];
     39   // CHECK: {{^}}      ^
     40   // CHECK-NOT: fix-it
     41   struct T {
     42     int [];
     43     // expected-error@-1{{expected member name or ';' after declaration specifiers}}
     44     // CHECK: {{^}}    int [];
     45     // CHECK: {{^}}    ~~~ ^
     46     // CHECK-NOT: fix-it
     47   };
     48 }
     49 
     50 void test3() {
     51   int [5] *;
     52   // expected-error@-1{{expected identifier or '('}}
     53   // CHECK: {{^}}  int [5] *;
     54   // CHECK: {{^}}           ^
     55   // CHECK-NOT: fix-it
     56   // expected-error@-5{{brackets go after the identifier}}
     57   // CHECK: {{^}}  int [5] *;
     58   // CHECK: {{^}}      ~~~~ ^
     59   // CHECK: {{^}}          ()[5]
     60   // CHECK: fix-it:{{.*}}:{[[@LINE-9]]:7-[[@LINE-9]]:11}:""
     61   // CHECK: fix-it:{{.*}}:{[[@LINE-10]]:11-[[@LINE-10]]:11}:"("
     62   // CHECK: fix-it:{{.*}}:{[[@LINE-11]]:12-[[@LINE-11]]:12}:")[5]"
     63 
     64   int [5] * a;
     65   // expected-error@-1{{brackets go after the identifier}}
     66   // CHECK: {{^}}  int [5] * a;
     67   // CHECK: {{^}}      ~~~~   ^
     68   // CHECK: {{^}}          (  )[5]
     69   // CHECK: fix-it:{{.*}}:{[[@LINE-5]]:7-[[@LINE-5]]:11}:""
     70   // CHECK: fix-it:{{.*}}:{[[@LINE-6]]:11-[[@LINE-6]]:11}:"("
     71   // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:14-[[@LINE-7]]:14}:")[5]"
     72 
     73   int *b[5] = a;  // expected-error{{}} a should not be corrected to type b
     74 
     75   int (*c)[5] = a;  // a should be the same type as c
     76 }
     77 #endif
     78 
     79 // CHECK: 8 errors generated.
     80