1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s 26871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor 36871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor// PR3588 46871981fbccba9e8a63997d58245ec0add114f49Douglas Gregorvoid g0(int, int); 55862f0e1ac29c5af8089b4bf119fd4493f6ab58cTed Kremenekvoid g0(); // expected-note{{previous declaration is here}} expected-note{{'g0' declared here}} 66871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor 76871981fbccba9e8a63997d58245ec0add114f49Douglas Gregorvoid f0() { 86871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor g0(1, 2, 3); // expected-error{{too many arguments to function call}} 96871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor} 106871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor 116871981fbccba9e8a63997d58245ec0add114f49Douglas Gregorvoid g0(int); // expected-error{{conflicting types for 'g0'}} 126871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor 136871981fbccba9e8a63997d58245ec0add114f49Douglas Gregorint g1(int, int); 146871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor 156871981fbccba9e8a63997d58245ec0add114f49Douglas Gregortypedef int INT; 166871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor 176871981fbccba9e8a63997d58245ec0add114f49Douglas GregorINT g1(x, y) 186871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor int x; 196871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor int y; 206871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor{ 216871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor return x + y; 226871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor} 236871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor 246871981fbccba9e8a63997d58245ec0add114f49Douglas Gregorint g2(int, int); // expected-note{{previous declaration is here}} 256871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor 266871981fbccba9e8a63997d58245ec0add114f49Douglas GregorINT g2(x) // expected-error{{conflicting types for 'g2'}} 276871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor int x; 286871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor{ 296871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor return x; 306871981fbccba9e8a63997d58245ec0add114f49Douglas Gregor} 3104495c859f81e440748a9b86baa2913461652bb0Douglas Gregor 3204495c859f81e440748a9b86baa2913461652bb0Douglas Gregorvoid test() { 3304495c859f81e440748a9b86baa2913461652bb0Douglas Gregor int f1; 3404495c859f81e440748a9b86baa2913461652bb0Douglas Gregor { 3504495c859f81e440748a9b86baa2913461652bb0Douglas Gregor void f1(double); 3604495c859f81e440748a9b86baa2913461652bb0Douglas Gregor { 3704495c859f81e440748a9b86baa2913461652bb0Douglas Gregor void f1(double); // expected-note{{previous declaration is here}} 3804495c859f81e440748a9b86baa2913461652bb0Douglas Gregor { 3904495c859f81e440748a9b86baa2913461652bb0Douglas Gregor int f1(int); // expected-error{{conflicting types for 'f1'}} 4004495c859f81e440748a9b86baa2913461652bb0Douglas Gregor } 4104495c859f81e440748a9b86baa2913461652bb0Douglas Gregor } 4204495c859f81e440748a9b86baa2913461652bb0Douglas Gregor } 4304495c859f81e440748a9b86baa2913461652bb0Douglas Gregor} 4404495c859f81e440748a9b86baa2913461652bb0Douglas Gregor 4504495c859f81e440748a9b86baa2913461652bb0Douglas Gregorextern void g3(int); // expected-note{{previous declaration is here}} 4604495c859f81e440748a9b86baa2913461652bb0Douglas Gregorstatic void g3(int x) { } // expected-error{{static declaration of 'g3' follows non-static declaration}} 4704495c859f81e440748a9b86baa2913461652bb0Douglas Gregor 4804495c859f81e440748a9b86baa2913461652bb0Douglas Gregorvoid test2() { 49d6f7e9dccd0fa8a5a15d7478324c0ae229fc5e1eDouglas Gregor extern int f2; // expected-note 2 {{previous definition is here}} 5004495c859f81e440748a9b86baa2913461652bb0Douglas Gregor { 5104495c859f81e440748a9b86baa2913461652bb0Douglas Gregor void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}} 5204495c859f81e440748a9b86baa2913461652bb0Douglas Gregor } 5304495c859f81e440748a9b86baa2913461652bb0Douglas Gregor 5404495c859f81e440748a9b86baa2913461652bb0Douglas Gregor { 5504495c859f81e440748a9b86baa2913461652bb0Douglas Gregor int f2; 5604495c859f81e440748a9b86baa2913461652bb0Douglas Gregor { 57d6f7e9dccd0fa8a5a15d7478324c0ae229fc5e1eDouglas Gregor void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}} 5804495c859f81e440748a9b86baa2913461652bb0Douglas Gregor } 5904495c859f81e440748a9b86baa2913461652bb0Douglas Gregor } 6004495c859f81e440748a9b86baa2913461652bb0Douglas Gregor} 6125d944af5d8d665611e09956954f10896c1071f6Douglas Gregor 6225d944af5d8d665611e09956954f10896c1071f6Douglas Gregor// <rdar://problem/6127293> 6325d944af5d8d665611e09956954f10896c1071f6Douglas Gregorint outer1(int); // expected-note{{previous declaration is here}} 6425d944af5d8d665611e09956954f10896c1071f6Douglas Gregorstruct outer3 { }; 6525d944af5d8d665611e09956954f10896c1071f6Douglas Gregorint outer4(int); 6625d944af5d8d665611e09956954f10896c1071f6Douglas Gregorint outer5; // expected-note{{previous definition is here}} 6725d944af5d8d665611e09956954f10896c1071f6Douglas Gregorint *outer7(int); 6825d944af5d8d665611e09956954f10896c1071f6Douglas Gregor 6925d944af5d8d665611e09956954f10896c1071f6Douglas Gregorvoid outer_test() { 7025d944af5d8d665611e09956954f10896c1071f6Douglas Gregor int outer1(float); // expected-error{{conflicting types for 'outer1'}} 7125d944af5d8d665611e09956954f10896c1071f6Douglas Gregor int outer2(int); // expected-note{{previous declaration is here}} 7225d944af5d8d665611e09956954f10896c1071f6Douglas Gregor int outer3(int); // expected-note{{previous declaration is here}} 7325d944af5d8d665611e09956954f10896c1071f6Douglas Gregor int outer4(int); // expected-note{{previous declaration is here}} 7425d944af5d8d665611e09956954f10896c1071f6Douglas Gregor int outer5(int); // expected-error{{redefinition of 'outer5' as different kind of symbol}} 7525d944af5d8d665611e09956954f10896c1071f6Douglas Gregor int* outer6(int); // expected-note{{previous declaration is here}} 7625d944af5d8d665611e09956954f10896c1071f6Douglas Gregor int *outer7(int); 776393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor int outer8(int); 7825d944af5d8d665611e09956954f10896c1071f6Douglas Gregor 7925d944af5d8d665611e09956954f10896c1071f6Douglas Gregor int *ip7 = outer7(6); 8025d944af5d8d665611e09956954f10896c1071f6Douglas Gregor} 8125d944af5d8d665611e09956954f10896c1071f6Douglas Gregor 8225d944af5d8d665611e09956954f10896c1071f6Douglas Gregorint outer2(float); // expected-error{{conflicting types for 'outer2'}} 8325d944af5d8d665611e09956954f10896c1071f6Douglas Gregorint outer3(float); // expected-error{{conflicting types for 'outer3'}} 8425d944af5d8d665611e09956954f10896c1071f6Douglas Gregorint outer4(float); // expected-error{{conflicting types for 'outer4'}} 8525d944af5d8d665611e09956954f10896c1071f6Douglas Gregor 8625d944af5d8d665611e09956954f10896c1071f6Douglas Gregorvoid outer_test2(int x) { 8725d944af5d8d665611e09956954f10896c1071f6Douglas Gregor int* ip = outer6(x); // expected-warning{{use of out-of-scope declaration of 'outer6'}} 8825d944af5d8d665611e09956954f10896c1071f6Douglas Gregor int *ip2 = outer7(x); 8925d944af5d8d665611e09956954f10896c1071f6Douglas Gregor} 906393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor 916393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregorvoid outer_test3() { 926393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor int *(*fp)(int) = outer8; // expected-error{{use of undeclared identifier 'outer8'}} 936393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor} 946393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor 956393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregorstatic float outer8(float); // okay 96c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregor 97c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregorenum e { e1, e2 }; 98c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregor 99c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregor// GNU extension: prototypes and K&R function definitions 100c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregorint isroot(short x, // expected-note{{previous declaration is here}} 101c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregor enum e); 102c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregor 103c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregorint isroot(x, y) 104c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregor 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}} 105c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregor unsigned int y; 106c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregor{ 107c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregor return x == 1; 108c837656ca6d2a5b434923d7e2fd11d3a3c3bfa74Douglas Gregor} 10913d7a32774c51af4c314c9d1fa6229d0e1d099daDouglas Gregor 11013d7a32774c51af4c314c9d1fa6229d0e1d099daDouglas Gregor// PR3817 11113d7a32774c51af4c314c9d1fa6229d0e1d099daDouglas Gregorvoid *h0(unsigned a0, ...); 11213d7a32774c51af4c314c9d1fa6229d0e1d099daDouglas Gregorextern __typeof (h0) h1 __attribute__((__sentinel__)); 11313d7a32774c51af4c314c9d1fa6229d0e1d099daDouglas Gregorextern __typeof (h1) h1 __attribute__((__sentinel__)); 11413d7a32774c51af4c314c9d1fa6229d0e1d099daDouglas Gregor 11513d7a32774c51af4c314c9d1fa6229d0e1d099daDouglas Gregor// PR3840 11613d7a32774c51af4c314c9d1fa6229d0e1d099daDouglas Gregorvoid i0 (unsigned short a0); 11713d7a32774c51af4c314c9d1fa6229d0e1d099daDouglas Gregorextern __typeof (i0) i1; 11813d7a32774c51af4c314c9d1fa6229d0e1d099daDouglas Gregorextern __typeof (i1) i1; 119d1659a6bd96132ffab70613b23f5716424fa364fDouglas Gregor 120d1659a6bd96132ffab70613b23f5716424fa364fDouglas Gregortypedef int a(); 121d1659a6bd96132ffab70613b23f5716424fa364fDouglas Gregortypedef int a2(int*); 122d1659a6bd96132ffab70613b23f5716424fa364fDouglas Gregora x; 1235f970eee81372dfc6a1457c3d6d052af04e32a38Douglas Gregora2 x2; // expected-note{{passing argument to parameter here}} 124d1659a6bd96132ffab70613b23f5716424fa364fDouglas Gregorvoid test_x() { 125d1659a6bd96132ffab70613b23f5716424fa364fDouglas Gregor x(5); 126d4eea8362605807327735727a9098abe1eb23b19Douglas Gregor x2(5); // expected-warning{{incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'}} 127d1659a6bd96132ffab70613b23f5716424fa364fDouglas Gregor} 128b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor 1290511552e20c79ec48638038b9a10a70a34654e5cFariborz Jahanianenum e0 {one}; 130b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregorvoid f3(); 131b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregorvoid f3(enum e0 x) {} 132c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman 133c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedmanenum incomplete_enum; 134c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedmanvoid f4(); // expected-note {{previous declaration is here}} 135c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedmanvoid f4(enum incomplete_enum); // expected-error {{conflicting types for 'f4'}} 136