Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 6871981 | 2009-02-16 18:20:44 +0000 | [diff] [blame] | 2 | |
| 3 | // PR3588 |
| 4 | void g0(int, int); |
Ted Kremenek | 5862f0e | 2011-04-04 17:22:27 +0000 | [diff] [blame] | 5 | void g0(); // expected-note{{previous declaration is here}} expected-note{{'g0' declared here}} |
Douglas Gregor | 6871981 | 2009-02-16 18:20:44 +0000 | [diff] [blame] | 6 | |
| 7 | void f0() { |
| 8 | g0(1, 2, 3); // expected-error{{too many arguments to function call}} |
| 9 | } |
| 10 | |
| 11 | void g0(int); // expected-error{{conflicting types for 'g0'}} |
| 12 | |
| 13 | int g1(int, int); |
| 14 | |
| 15 | typedef int INT; |
| 16 | |
| 17 | INT g1(x, y) |
| 18 | int x; |
| 19 | int y; |
| 20 | { |
| 21 | return x + y; |
| 22 | } |
| 23 | |
| 24 | int g2(int, int); // expected-note{{previous declaration is here}} |
| 25 | |
| 26 | INT g2(x) // expected-error{{conflicting types for 'g2'}} |
| 27 | int x; |
| 28 | { |
| 29 | return x; |
| 30 | } |
Douglas Gregor | 04495c8 | 2009-02-24 01:23:02 +0000 | [diff] [blame] | 31 | |
| 32 | void test() { |
| 33 | int f1; |
| 34 | { |
| 35 | void f1(double); |
| 36 | { |
| 37 | void f1(double); // expected-note{{previous declaration is here}} |
| 38 | { |
| 39 | int f1(int); // expected-error{{conflicting types for 'f1'}} |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | extern void g3(int); // expected-note{{previous declaration is here}} |
| 46 | static void g3(int x) { } // expected-error{{static declaration of 'g3' follows non-static declaration}} |
| 47 | |
| 48 | void test2() { |
Douglas Gregor | d6f7e9d | 2009-02-24 20:03:32 +0000 | [diff] [blame] | 49 | extern int f2; // expected-note 2 {{previous definition is here}} |
Douglas Gregor | 04495c8 | 2009-02-24 01:23:02 +0000 | [diff] [blame] | 50 | { |
| 51 | void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}} |
| 52 | } |
| 53 | |
| 54 | { |
| 55 | int f2; |
| 56 | { |
Douglas Gregor | d6f7e9d | 2009-02-24 20:03:32 +0000 | [diff] [blame] | 57 | void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}} |
Douglas Gregor | 04495c8 | 2009-02-24 01:23:02 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
Douglas Gregor | 25d944a | 2009-02-24 04:26:15 +0000 | [diff] [blame] | 61 | |
| 62 | // <rdar://problem/6127293> |
| 63 | int outer1(int); // expected-note{{previous declaration is here}} |
| 64 | struct outer3 { }; |
| 65 | int outer4(int); |
| 66 | int outer5; // expected-note{{previous definition is here}} |
| 67 | int *outer7(int); |
| 68 | |
| 69 | void outer_test() { |
| 70 | int outer1(float); // expected-error{{conflicting types for 'outer1'}} |
| 71 | int outer2(int); // expected-note{{previous declaration is here}} |
| 72 | int outer3(int); // expected-note{{previous declaration is here}} |
| 73 | int outer4(int); // expected-note{{previous declaration is here}} |
| 74 | int outer5(int); // expected-error{{redefinition of 'outer5' as different kind of symbol}} |
| 75 | int* outer6(int); // expected-note{{previous declaration is here}} |
| 76 | int *outer7(int); |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 77 | int outer8(int); |
Douglas Gregor | 25d944a | 2009-02-24 04:26:15 +0000 | [diff] [blame] | 78 | |
| 79 | int *ip7 = outer7(6); |
| 80 | } |
| 81 | |
| 82 | int outer2(float); // expected-error{{conflicting types for 'outer2'}} |
| 83 | int outer3(float); // expected-error{{conflicting types for 'outer3'}} |
| 84 | int outer4(float); // expected-error{{conflicting types for 'outer4'}} |
| 85 | |
| 86 | void outer_test2(int x) { |
| 87 | int* ip = outer6(x); // expected-warning{{use of out-of-scope declaration of 'outer6'}} |
| 88 | int *ip2 = outer7(x); |
| 89 | } |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 90 | |
| 91 | void outer_test3() { |
| 92 | int *(*fp)(int) = outer8; // expected-error{{use of undeclared identifier 'outer8'}} |
| 93 | } |
| 94 | |
| 95 | static float outer8(float); // okay |
Douglas Gregor | c837656 | 2009-03-06 22:43:54 +0000 | [diff] [blame] | 96 | |
| 97 | enum e { e1, e2 }; |
| 98 | |
| 99 | // GNU extension: prototypes and K&R function definitions |
| 100 | int isroot(short x, // expected-note{{previous declaration is here}} |
| 101 | enum e); |
| 102 | |
| 103 | int isroot(x, y) |
| 104 | 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}} |
| 105 | unsigned int y; |
| 106 | { |
| 107 | return x == 1; |
| 108 | } |
Douglas Gregor | 13d7a32 | 2009-03-19 18:14:46 +0000 | [diff] [blame] | 109 | |
| 110 | // PR3817 |
| 111 | void *h0(unsigned a0, ...); |
| 112 | extern __typeof (h0) h1 __attribute__((__sentinel__)); |
| 113 | extern __typeof (h1) h1 __attribute__((__sentinel__)); |
| 114 | |
| 115 | // PR3840 |
| 116 | void i0 (unsigned short a0); |
| 117 | extern __typeof (i0) i1; |
| 118 | extern __typeof (i1) i1; |
Douglas Gregor | d1659a6 | 2009-03-23 16:26:51 +0000 | [diff] [blame] | 119 | |
| 120 | typedef int a(); |
| 121 | typedef int a2(int*); |
| 122 | a x; |
Douglas Gregor | 5f970ee | 2010-05-04 18:18:31 +0000 | [diff] [blame] | 123 | a2 x2; // expected-note{{passing argument to parameter here}} |
Douglas Gregor | d1659a6 | 2009-03-23 16:26:51 +0000 | [diff] [blame] | 124 | void test_x() { |
| 125 | x(5); |
Douglas Gregor | d4eea83 | 2010-04-09 00:35:39 +0000 | [diff] [blame] | 126 | x2(5); // expected-warning{{incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'}} |
Douglas Gregor | d1659a6 | 2009-03-23 16:26:51 +0000 | [diff] [blame] | 127 | } |
Douglas Gregor | b0f8eac | 2010-02-03 19:27:29 +0000 | [diff] [blame] | 128 | |
Fariborz Jahanian | 0511552 | 2010-05-28 22:23:22 +0000 | [diff] [blame] | 129 | enum e0 {one}; |
Douglas Gregor | b0f8eac | 2010-02-03 19:27:29 +0000 | [diff] [blame] | 130 | void f3(); |
| 131 | void f3(enum e0 x) {} |