function-redecl.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // PR3588
  3. void g0(int, int);
  4. void g0(); // expected-note{{previous declaration is here}} expected-note{{'g0' declared here}}
  5. void f0() {
  6. g0(1, 2, 3); // expected-error{{too many arguments to function call}}
  7. }
  8. void g0(int); // expected-error{{conflicting types for 'g0'}}
  9. int g1(int, int);
  10. typedef int INT;
  11. INT g1(x, y)
  12. int x;
  13. int y;
  14. {
  15. return x + y;
  16. }
  17. int g2(int, int); // expected-note{{previous declaration is here}}
  18. INT g2(x) // expected-error{{conflicting types for 'g2'}}
  19. int x;
  20. {
  21. return x;
  22. }
  23. void test() {
  24. int f1;
  25. {
  26. void f1(double);
  27. {
  28. void f1(double); // expected-note{{previous declaration is here}}
  29. {
  30. int f1(int); // expected-error{{conflicting types for 'f1'}}
  31. }
  32. }
  33. }
  34. }
  35. extern void g3(int); // expected-note{{previous declaration is here}}
  36. static void g3(int x) { } // expected-error{{static declaration of 'g3' follows non-static declaration}}
  37. void test2() {
  38. extern int f2; // expected-note 2 {{previous definition is here}}
  39. {
  40. void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}}
  41. }
  42. {
  43. int f2;
  44. {
  45. void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}}
  46. }
  47. }
  48. }
  49. // <rdar://problem/6127293>
  50. int outer1(int); // expected-note{{previous declaration is here}}
  51. struct outer3 { };
  52. int outer4(int); // expected-note{{previous declaration is here}}
  53. int outer5; // expected-note{{previous definition is here}}
  54. int *outer7(int);
  55. void outer_test() {
  56. int outer1(float); // expected-error{{conflicting types for 'outer1'}}
  57. int outer2(int); // expected-note{{previous declaration is here}}
  58. int outer3(int); // expected-note{{previous declaration is here}}
  59. int outer4(int);
  60. int outer5(int); // expected-error{{redefinition of 'outer5' as different kind of symbol}}
  61. int* outer6(int); // expected-note{{previous declaration is here}}
  62. int *outer7(int);
  63. int outer8(int);
  64. int *ip7 = outer7(6);
  65. }
  66. int outer2(float); // expected-error{{conflicting types for 'outer2'}}
  67. int outer3(float); // expected-error{{conflicting types for 'outer3'}}
  68. int outer4(float); // expected-error{{conflicting types for 'outer4'}}
  69. void outer_test2(int x) {
  70. int* ip = outer6(x); // expected-warning{{use of out-of-scope declaration of 'outer6'}}
  71. int *ip2 = outer7(x);
  72. }
  73. void outer_test3() {
  74. int *(*fp)(int) = outer8; // expected-error{{use of undeclared identifier 'outer8'}}
  75. }
  76. enum e { e1, e2 };
  77. // GNU extension: prototypes and K&R function definitions
  78. int isroot(short x, // expected-note{{previous declaration is here}}
  79. enum e);
  80. int isroot(x, y)
  81. short x; // expected-warning{{promoted type 'int' of K&R function parameter is not compatible with the parameter type 'short' declared in a previous prototype}}
  82. unsigned int y;
  83. {
  84. return x == 1;
  85. }
  86. // PR3817
  87. void *h0(unsigned a0, ...);
  88. extern __typeof (h0) h1 __attribute__((__sentinel__));
  89. extern __typeof (h1) h1 __attribute__((__sentinel__));
  90. // PR3840
  91. void i0 (unsigned short a0);
  92. extern __typeof (i0) i1;
  93. extern __typeof (i1) i1;
  94. typedef int a();
  95. typedef int a2(int*);
  96. a x;
  97. a2 x2; // expected-note{{passing argument to parameter here}}
  98. void test_x() {
  99. x(5);
  100. x2(5); // expected-warning{{incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'}}
  101. }
  102. enum e0 {one};
  103. void f3();
  104. void f3(enum e0 x) {}
  105. enum incomplete_enum;
  106. void f4(); // expected-note {{previous declaration is here}}
  107. void f4(enum incomplete_enum); // expected-error {{conflicting types for 'f4'}}