function.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
  2. // PR1892, PR11354
  3. void f(double a[restrict][5]) { __typeof(a) x = 10; } // expected-warning {{(aka 'double (*restrict)[5]')}}
  4. int foo (__const char *__path);
  5. int foo(__const char *__restrict __file);
  6. void func(const char*); // expected-note {{previous declaration is here}}
  7. void func(char*); // expected-error{{conflicting types for 'func'}}
  8. void g(int (*)(const void **, const void **));
  9. void g(int (*compar)()) {
  10. }
  11. void h(); // expected-note {{previous declaration is here}}
  12. void h (const char *fmt, ...) {} // expected-error{{conflicting types for 'h'}}
  13. // PR1965
  14. int t5(b); // expected-error {{parameter list without types}}
  15. int t6(int x, g); // expected-warning {{type specifier missing, defaults to 'int'}}
  16. int t7(, ); // expected-error {{expected parameter declarator}} expected-error {{expected parameter declarator}}
  17. int t8(, int a); // expected-error {{expected parameter declarator}}
  18. int t9(int a, ); // expected-error {{expected parameter declarator}}
  19. // PR2042
  20. void t10(){}
  21. void t11(){t10(1);} // expected-warning{{too many arguments}}
  22. // PR3208
  23. void t12(int) {} // expected-error{{parameter name omitted}}
  24. // PR2790
  25. void t13() {
  26. return 0; // expected-error {{void function 't13' should not return a value}}
  27. }
  28. int t14() {
  29. return; // expected-error {{non-void function 't14' should return a value}}
  30. }
  31. // <rdar://problem/6097326>
  32. y(y) { return y; } // expected-warning{{parameter 'y' was not declared, defaulting to type 'int'}} \
  33. // expected-warning{{type specifier missing, defaults to 'int'}}
  34. // PR3137, <rdar://problem/6127293>
  35. extern int g0_3137(void);
  36. void f0_3137() {
  37. int g0_3137(void);
  38. }
  39. void f1_3137() {
  40. int (*fp)(void) = g0_3137;
  41. }
  42. void f1static() {
  43. static void f2static(int); // expected-error{{function declared in block scope cannot have 'static' storage class}}
  44. register void f2register(int); // expected-error{{illegal storage class on function}}
  45. }
  46. struct incomplete_test a(void) {} // expected-error{{incomplete result type 'struct incomplete_test' in function definition}} \
  47. // expected-note{{forward declaration of 'struct incomplete_test'}}
  48. extern __inline
  49. __attribute__((__gnu_inline__))
  50. void gnu_inline1() {}
  51. void
  52. __attribute__((__gnu_inline__)) // expected-warning {{'gnu_inline' attribute requires function to be marked 'inline', attribute ignored}}
  53. gnu_inline2() {}
  54. // rdar://6802350
  55. inline foo_t invalid_type() { // expected-error {{unknown type name 'foo_t'}}
  56. }
  57. typedef void fn_t(void);
  58. fn_t t17;
  59. // PR4049
  60. unknown_type t18(void*) { // expected-error {{unknown type name 'unknown_type'}} expected-error{{parameter name omitted}}
  61. }
  62. unknown_type t19(int* P) { // expected-error {{unknown type name 'unknown_type'}}
  63. P = P+1; // no warning.
  64. }
  65. // missing ',' before '...'
  66. void t20(int i...) { } // expected-error {{requires a comma}}
  67. int n;
  68. void t21(int n, int (*array)[n]);
  69. int func_e(int x) {
  70. int func_n(int y) { // expected-error {{function definition is not allowed here}}
  71. if (y > 22) {
  72. return y+2;
  73. } else {
  74. return y-2;
  75. }
  76. }
  77. return x + 3;
  78. }
  79. void decays(int a[3][3]); // expected-note {{passing argument to parameter 'a' here}}
  80. void no_decay(int (*a)[3]); // expected-note {{passing argument to parameter 'a' here}}
  81. void t22(int *ptr, int (*array)[3]) {
  82. decays(ptr); // expected-warning {{incompatible pointer types passing 'int *' to parameter of type 'int (*)[3]'}}
  83. no_decay(ptr); // expected-warning {{incompatible pointer types passing 'int *' to parameter of type 'int (*)[3]'}}
  84. decays(array);
  85. no_decay(array);
  86. }
  87. void const Bar (void); // ok on decl
  88. // PR 20146
  89. void const Bar (void) // expected-warning {{function cannot return qualified void type 'const void'}}
  90. {
  91. }