xref: /aosp_15_r20/external/clang/test/Sema/merge-decls.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 %s -verify -fsyntax-only
2*67e74705SXin Li 
3*67e74705SXin Li void foo(void);
foo(void)4*67e74705SXin Li void foo(void) {}
5*67e74705SXin Li void foo(void);
6*67e74705SXin Li void foo(void); // expected-note {{previous declaration is here}}
7*67e74705SXin Li 
8*67e74705SXin Li void foo(int); // expected-error {{conflicting types for 'foo'}}
9*67e74705SXin Li 
funcdef()10*67e74705SXin Li int funcdef()
11*67e74705SXin Li {
12*67e74705SXin Li  return 0;
13*67e74705SXin Li }
14*67e74705SXin Li 
15*67e74705SXin Li int funcdef();
16*67e74705SXin Li 
funcdef2()17*67e74705SXin Li int funcdef2() { return 0; } // expected-note {{previous definition is here}}
funcdef2()18*67e74705SXin Li int funcdef2() { return 0; } // expected-error {{redefinition of 'funcdef2'}}
19*67e74705SXin Li 
20*67e74705SXin Li // PR2502
21*67e74705SXin Li void (*f)(void);
22*67e74705SXin Li void (*f)() = 0;
23*67e74705SXin Li 
24*67e74705SXin Li typedef __attribute__(( ext_vector_type(2) )) int Vi2;
25*67e74705SXin Li typedef __attribute__(( ext_vector_type(2) )) float Vf2;
26*67e74705SXin Li 
27*67e74705SXin Li Vf2 g0; // expected-note {{previous definition is here}}
28*67e74705SXin Li Vi2 g0; // expected-error {{redefinition of 'g0'}}
29*67e74705SXin Li 
30*67e74705SXin Li _Complex int g1; // expected-note {{previous definition is here}}
31*67e74705SXin Li _Complex float g1; // expected-error {{redefinition of 'g1'}}
32*67e74705SXin Li 
33*67e74705SXin Li // rdar://6096412
34*67e74705SXin Li extern char i6096412[10];
35*67e74705SXin Li extern char i6096412[];
foo6096412(void)36*67e74705SXin Li void foo6096412(void) {
37*67e74705SXin Li   int x = sizeof(i6096412);
38*67e74705SXin Li }
39*67e74705SXin Li 
40*67e74705SXin Li 
41*67e74705SXin Li typedef int test1_IA[];
42*67e74705SXin Li typedef int test1_A10[10];
43*67e74705SXin Li static test1_A10 *test1_f(void);
test1_g(void)44*67e74705SXin Li void test1_g(void)
45*67e74705SXin Li {
46*67e74705SXin Li   {
47*67e74705SXin Li     extern test1_IA  *test1_f(void);
48*67e74705SXin Li   }
49*67e74705SXin Li   (void)sizeof(*test1_f());
50*67e74705SXin Li }
51*67e74705SXin Li 
52*67e74705SXin Li typedef int test2_IA[];
53*67e74705SXin Li typedef int test2_A10[10];
54*67e74705SXin Li 
55*67e74705SXin Li static test2_A10 *test2_f(void);
56*67e74705SXin Li static test2_IA  *test2_f(void);
57*67e74705SXin Li 
test2_g(void)58*67e74705SXin Li void test2_g(void)
59*67e74705SXin Li {
60*67e74705SXin Li   (void)sizeof(*test2_f());
61*67e74705SXin Li }
62*67e74705SXin Li 
63*67e74705SXin Li int (*test3_f())[10];
64*67e74705SXin Li int (*test3_f())[];
65*67e74705SXin Li int test3_k = sizeof(*test3_f());
66*67e74705SXin Li 
67*67e74705SXin Li void test4_f(int);
test4_f(a)68*67e74705SXin Li void test4_f(a)
69*67e74705SXin Li   char a;
70*67e74705SXin Li {
71*67e74705SXin Li   int v[sizeof(a) == 1 ? 1 : -1];
72*67e74705SXin Li }
73*67e74705SXin Li 
74*67e74705SXin Li int test5_f(int (*)[10]);
test5_f(int (* x)[])75*67e74705SXin Li int test5_f(int (*x)[]) {
76*67e74705SXin Li   return sizeof(*x); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
77*67e74705SXin Li }
78*67e74705SXin Li 
79*67e74705SXin Li void test6_f(int (*a)[11]);
80*67e74705SXin Li void test6_f(a)
81*67e74705SXin Li    int (*a)[];
82*67e74705SXin Li {}
test6_g()83*67e74705SXin Li void test6_g() {
84*67e74705SXin Li   int arr[10];
85*67e74705SXin Li   test6_f(&arr); // expected-warning {{incompatible pointer types passing 'int (*)[10]' to parameter of type 'int (*)[11]}}
86*67e74705SXin Li }
87*67e74705SXin Li 
88*67e74705SXin Li void test7_f(int (*)[10]);
89*67e74705SXin Li void test7_f(int (*)[]); // expected-note {{passing argument to parameter here}}
test7_g()90*67e74705SXin Li void test7_g() {
91*67e74705SXin Li   int x[5];
92*67e74705SXin Li   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
93*67e74705SXin Li }
94