declarators.c 4.2 KB

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