xref: /aosp_15_r20/external/clang/test/Sema/tentative-decls.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 %s -fsyntax-only -Wprivate-extern -verify
2*67e74705SXin Li 
3*67e74705SXin Li // PR3310
4*67e74705SXin Li struct a x1; // expected-note 2{{forward declaration of 'struct a'}}
5*67e74705SXin Li static struct a x2; // expected-warning{{tentative definition of variable with internal linkage has incomplete non-array type 'struct a'}}
6*67e74705SXin Li struct a x3[10]; // expected-error{{array has incomplete element type 'struct a'}}
7*67e74705SXin Li struct a {int x;};
8*67e74705SXin Li static struct a x2_okay;
9*67e74705SXin Li struct a x3_okay[10];
10*67e74705SXin Li struct b x4; // expected-error{{tentative definition has type 'struct b' that is never completed}} \
11*67e74705SXin Li             // expected-note{{forward declaration of 'struct b'}}
12*67e74705SXin Li 
13*67e74705SXin Li const int a [1] = {1};
14*67e74705SXin Li extern const int a[];
15*67e74705SXin Li 
16*67e74705SXin Li extern const int b[];
17*67e74705SXin Li const int b [1] = {1};
18*67e74705SXin Li 
19*67e74705SXin Li extern const int c[] = {1}; // expected-warning{{'extern' variable has an initializer}}
20*67e74705SXin Li const int c[];
21*67e74705SXin Li 
22*67e74705SXin Li int i1 = 1; // expected-note {{previous definition is here}}
23*67e74705SXin Li int i1 = 2; // expected-error {{redefinition of 'i1'}}
24*67e74705SXin Li int i1;
25*67e74705SXin Li int i1;
26*67e74705SXin Li extern int i5; // expected-note {{previous declaration is here}}
27*67e74705SXin Li static int i5; // expected-error{{static declaration of 'i5' follows non-static declaration}}
28*67e74705SXin Li 
29*67e74705SXin Li static int i2 = 5; // expected-note 1 {{previous definition is here}}
30*67e74705SXin Li int i2 = 3; // expected-error{{non-static declaration of 'i2' follows static declaration}}
31*67e74705SXin Li 
32*67e74705SXin Li static int i3 = 5;
33*67e74705SXin Li extern int i3;
34*67e74705SXin Li 
35*67e74705SXin Li // rdar://7703982
36*67e74705SXin Li __private_extern__ int pExtern; // expected-warning {{use of __private_extern__ on a declaration may not produce external symbol private to the linkage unit and is deprecated}} \
37*67e74705SXin Li // expected-note {{use __attribute__((visibility("hidden"))) attribute instead}}
38*67e74705SXin Li int pExtern = 0;
39*67e74705SXin Li 
40*67e74705SXin Li int i4;
41*67e74705SXin Li int i4;
42*67e74705SXin Li extern int i4;
43*67e74705SXin Li 
44*67e74705SXin Li int (*pToArray)[];
45*67e74705SXin Li int (*pToArray)[8];
46*67e74705SXin Li 
47*67e74705SXin Li int redef[10];
48*67e74705SXin Li int redef[];  // expected-note {{previous definition is here}}
49*67e74705SXin Li int redef[11]; // expected-error{{redefinition of 'redef'}}
50*67e74705SXin Li 
func()51*67e74705SXin Li void func() {
52*67e74705SXin Li   extern int i6; // expected-note {{previous declaration is here}}
53*67e74705SXin Li   static int i6; // expected-error{{static declaration of 'i6' follows non-static declaration}}
54*67e74705SXin Li }
55*67e74705SXin Li 
func2(void)56*67e74705SXin Li void func2(void)
57*67e74705SXin Li {
58*67e74705SXin Li   extern double *p;
59*67e74705SXin Li   extern double *p;
60*67e74705SXin Li }
61*67e74705SXin Li 
62*67e74705SXin Li // <rdar://problem/6808352>
63*67e74705SXin Li static int a0[];
64*67e74705SXin Li static int b0;
65*67e74705SXin Li 
66*67e74705SXin Li static int a0[] = { 4 };
67*67e74705SXin Li static int b0 = 5;
68