xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/var-redecl.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc int outer1; // expected-note{{previous definition is here}}
4f4a2713aSLionel Sambuc extern int outer2; // expected-note{{previous definition is here}}
5f4a2713aSLionel Sambuc int outer4;
6f4a2713aSLionel Sambuc int outer4; // expected-note{{previous definition is here}}
7*0a6a1f1dSLionel Sambuc int outer5;
8f4a2713aSLionel Sambuc int outer6(float); // expected-note{{previous definition is here}}
9f4a2713aSLionel Sambuc int outer7(float);
10f4a2713aSLionel Sambuc 
outer_test()11f4a2713aSLionel Sambuc void outer_test() {
12f4a2713aSLionel Sambuc   extern float outer1; // expected-error{{redefinition of 'outer1' with a different type}}
13f4a2713aSLionel Sambuc   extern float outer2; // expected-error{{redefinition of 'outer2' with a different type}}
14f4a2713aSLionel Sambuc   extern float outer3; // expected-note{{previous definition is here}}
15f4a2713aSLionel Sambuc   double outer4;
16*0a6a1f1dSLionel Sambuc   extern int outer5; // expected-note{{previous definition is here}}
17f4a2713aSLionel Sambuc   extern int outer6; // expected-error{{redefinition of 'outer6' as different kind of symbol}}
18f4a2713aSLionel Sambuc   int outer7;
19f4a2713aSLionel Sambuc   extern int outer8; // expected-note{{previous definition is here}}
20f4a2713aSLionel Sambuc   extern int outer9;
21f4a2713aSLionel Sambuc   {
22f4a2713aSLionel Sambuc     extern int outer9; // expected-note{{previous definition is here}}
23f4a2713aSLionel Sambuc   }
24f4a2713aSLionel Sambuc }
25f4a2713aSLionel Sambuc 
26f4a2713aSLionel Sambuc int outer3; // expected-error{{redefinition of 'outer3' with a different type}}
27f4a2713aSLionel Sambuc float outer4; // expected-error{{redefinition of 'outer4' with a different type}}
28f4a2713aSLionel Sambuc float outer5;  // expected-error{{redefinition of 'outer5' with a different type}}
29f4a2713aSLionel Sambuc int outer8(int); // expected-error{{redefinition of 'outer8' as different kind of symbol}}
30f4a2713aSLionel Sambuc float outer9; // expected-error{{redefinition of 'outer9' with a different type}}
31f4a2713aSLionel Sambuc 
32f4a2713aSLionel Sambuc extern int outer13; // expected-note{{previous definition is here}}
outer_shadowing_test()33f4a2713aSLionel Sambuc void outer_shadowing_test() {
34f4a2713aSLionel Sambuc   extern int outer10;
35f4a2713aSLionel Sambuc   extern int outer11; // expected-note{{previous definition is here}}
36f4a2713aSLionel Sambuc   extern int outer12; // expected-note{{previous definition is here}}
37f4a2713aSLionel Sambuc   {
38f4a2713aSLionel Sambuc     float outer10;
39f4a2713aSLionel Sambuc     float outer11;
40f4a2713aSLionel Sambuc     float outer12;
41f4a2713aSLionel Sambuc     {
42f4a2713aSLionel Sambuc       extern int outer10; // okay
43f4a2713aSLionel Sambuc       extern float outer11; // expected-error{{redefinition of 'outer11' with a different type}}
44f4a2713aSLionel Sambuc       static double outer12;
45f4a2713aSLionel Sambuc       {
46f4a2713aSLionel Sambuc         extern float outer12; // expected-error{{redefinition of 'outer12' with a different type}}
47f4a2713aSLionel Sambuc         extern float outer13; // expected-error{{redefinition of 'outer13' with a different type}}
48f4a2713aSLionel Sambuc       }
49f4a2713aSLionel Sambuc     }
50f4a2713aSLionel Sambuc   }
51f4a2713aSLionel Sambuc }
52f4a2713aSLionel Sambuc 
g18(void)53f4a2713aSLionel Sambuc void g18(void) { // expected-note{{'g18' declared here}}
54f4a2713aSLionel Sambuc   extern int g19;
55f4a2713aSLionel Sambuc }
56f4a2713aSLionel Sambuc int *p=&g19; // expected-error{{use of undeclared identifier 'g19'}} \
57f4a2713aSLionel Sambuc              // expected-warning{{incompatible pointer types}}
58f4a2713aSLionel Sambuc 
59f4a2713aSLionel Sambuc // PR3645
60f4a2713aSLionel Sambuc static int a;
61*0a6a1f1dSLionel Sambuc extern int a; // expected-note {{previous declaration is here}}
62f4a2713aSLionel Sambuc int a;	// expected-error {{non-static declaration of 'a' follows static declaration}}
63*0a6a1f1dSLionel Sambuc 
f(int x)64*0a6a1f1dSLionel Sambuc void f(int x) { // expected-note {{previous definition is here}}
65*0a6a1f1dSLionel Sambuc   extern int x; // expected-error {{extern declaration of 'x' follows non-extern declaration}}
66*0a6a1f1dSLionel Sambuc }
67*0a6a1f1dSLionel Sambuc 
68*0a6a1f1dSLionel Sambuc extern int b[];
g20()69*0a6a1f1dSLionel Sambuc void g20() { extern int b[3]; } // expected-note{{previous definition is here}}
g21()70*0a6a1f1dSLionel Sambuc void g21() { extern int b[4]; } // expected-error{{redefinition of 'b' with a different type: 'int [4]' vs 'int [3]'}}
71