Home | History | Annotate | Download | only in Parser
      1 // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
      2 
      3 extern int a1[];
      4 
      5 void f0();
      6 void f1(int [*]);
      7 void f2(int [const *]);
      8 void f3(int [volatile const*]);
      9 int f4(*XX)(void); /* expected-error {{cannot return}} expected-warning {{type specifier missing, defaults to 'int'}} */
     10 
     11 char ((((*X))));
     12 
     13 void (*signal(int, void (*)(int)))(int);
     14 
     15 int aaaa, ***C, * const D, B(int);
     16 
     17 int *A;
     18 
     19 struct str;
     20 
     21 void test2(int *P, int A) {
     22   struct str;
     23 
     24   // Hard case for array decl, not Array[*].
     25   int Array[*(int*)P+A];
     26 }
     27 
     28 typedef int atype;
     29 void test3(x,
     30            atype         /* expected-error {{unexpected type name 'atype': expected identifier}} */
     31           ) int x, atype; {}
     32 
     33 void test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */
     34 
     35 
     36 // PR3031
     37 int (test5), ;  // expected-error {{expected identifier or '('}}
     38 
     39 
     40 
     41 // PR3963 & rdar://6759604 - test error recovery for mistyped "typenames".
     42 
     43 foo_t *d;      // expected-error {{unknown type name 'foo_t'}}
     44 foo_t a;   // expected-error {{unknown type name 'foo_t'}}
     45 int test6() { return a; }  // a should be declared.
     46 
     47 // Use of tagged type without tag. rdar://6783347
     48 struct xyz { int y; };
     49 enum myenum { ASDFAS };
     50 xyz b;         // expected-error {{must use 'struct' tag to refer to type 'xyz'}}
     51 myenum c;      // expected-error {{must use 'enum' tag to refer to type 'myenum'}}
     52 
     53 float *test7() {
     54   // We should recover 'b' by parsing it with a valid type of "struct xyz", which
     55   // allows us to diagnose other bad things done with y, such as this.
     56   return &b.y;   // expected-warning {{incompatible pointer types returning 'int *' from a function with result type 'float *'}}
     57 }
     58 
     59 struct xyz test8() { return a; }  // a should be be marked invalid, no diag.
     60 
     61 
     62 // Verify that implicit int still works.
     63 static f;      // expected-warning {{type specifier missing, defaults to 'int'}}
     64 static g = 4;  // expected-warning {{type specifier missing, defaults to 'int'}}
     65 static h        // expected-warning {{type specifier missing, defaults to 'int'}}
     66       __asm__("foo");
     67 
     68 
     69 struct test9 {
     70   int x  // expected-error {{expected ';' at end of declaration list}}
     71   int y;
     72   int z  // expected-warning {{expected ';' at end of declaration list}}
     73 };
     74 
     75 // PR6208
     76 struct test10 { int a; } static test10x;
     77 struct test11 { int a; } const test11x;
     78 
     79 // PR6216
     80 void test12() {
     81   (void)__builtin_offsetof(struct { char c; int i; }, i);
     82 }
     83 
     84 // rdar://7608537
     85 struct test13 { int a; } (test13x);
     86 
     87 // <rdar://problem/8044088>
     88 struct X<foo::int> { }; // expected-error{{expected identifier or '('}}
     89 
     90 
     91 // PR7617 - error recovery on missing ;.
     92 
     93 void test14()  // expected-error {{expected ';' after top level declarator}}
     94 
     95 void test14a();
     96 void *test14b = (void*)test14a; // Make sure test14a didn't get skipped.
     97 
     98 // rdar://problem/8358508
     99 long struct X { int x; } test15(); // expected-error {{'long struct' is invalid}}
    100 
    101 void test16(i) int i j; { } // expected-error {{expected ';' at end of declaration}}
    102 void test17(i, j) int i, j k; { } // expected-error {{expected ';' at end of declaration}}
    103 void knrNoSemi(i) int i { } // expected-error {{expected ';' at end of declaration}}
    104 
    105 
    106 // PR12595
    107 void test18() {
    108   int x = 4+(5-12));  // expected-error {{extraneous ')' before ';'}}
    109 }
    110 
    111 enum E1 { e1 }: // expected-error {{expected ';'}}
    112 struct EnumBitfield { // expected-warning {{struct without named members is a GNU extension}}
    113   enum E2 { e2 } : 4; // ok
    114   struct S { int n; }: // expected-error {{expected ';'}}
    115 
    116 };
    117 
    118 // PR10982
    119 enum E11 {
    120   A1 = 1,
    121 };
    122 
    123 enum E12 {
    124   ,  // expected-error{{expected identifier}}
    125   A2
    126 };
    127 void func_E12(enum E12 *p) { *p = A2; }
    128 
    129 enum E13 {
    130   1D,  // expected-error{{expected identifier}}
    131   A3
    132 };
    133 void func_E13(enum E13 *p) { *p = A3; }
    134 
    135 enum E14 {
    136   A4 12,  // expected-error{{expected '= constant-expression' or end of enumerator definition}}
    137   A4a
    138 };
    139 void func_E14(enum E14 *p) { *p = A4a; }
    140 
    141 enum E15 {
    142   A5=12 4,  // expected-error{{expected '}' or ','}}
    143   A5a
    144 };
    145 void func_E15(enum E15 *p) { *p = A5a; }
    146 
    147 enum E16 {
    148   A6;  // expected-error{{expected '= constant-expression' or end of enumerator definition}}
    149   A6a
    150 };
    151