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