14cc83c2b0aed5ab06081ea3250426c3a7e58df93Fariborz Jahanian// RUN: %clang_cc1 %s -fsyntax-only -Wprivate-extern -verify
2b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroff
3a03aca82de5259846d4ef38db11b8116398d2222Douglas Gregor// PR3310
4a03aca82de5259846d4ef38db11b8116398d2222Douglas Gregorstruct a x1; // expected-note 2{{forward declaration of 'struct a'}}
5ec8b59ffc30c65051070e6d6cbb8e4b419210d18Douglas Gregorstatic struct a x2; // expected-warning{{tentative definition of variable with internal linkage has incomplete non-array type 'struct a'}}
6a03aca82de5259846d4ef38db11b8116398d2222Douglas Gregorstruct a x3[10]; // expected-error{{array has incomplete element type 'struct a'}}
7a03aca82de5259846d4ef38db11b8116398d2222Douglas Gregorstruct a {int x;};
8275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregorstatic struct a x2_okay;
9275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregorstruct a x3_okay[10];
10275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregorstruct b x4; // expected-error{{tentative definition has type 'struct b' that is never completed}} \
11275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregor            // expected-note{{forward declaration of 'struct b'}}
12a03aca82de5259846d4ef38db11b8116398d2222Douglas Gregor
13b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroffconst int a [1] = {1};
14b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroffextern const int a[];
15b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroff
16b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroffextern const int b[];
17b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroffconst int b [1] = {1};
18b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroff
19b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroffextern const int c[] = {1}; // expected-warning{{'extern' variable has an initializer}}
20b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroffconst int c[];
21b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroff
225f4a6829dc58cab2f76e2b98492859aa3b91e3f2Chris Lattnerint i1 = 1; // expected-note {{previous definition is here}}
23cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregorint i1 = 2; // expected-error {{redefinition of 'i1'}}
24ff9eb1fe0a16a34c355db0d1bc4a9d0f7a276c73Steve Naroffint i1;
25b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroffint i1;
26eaaebc7cf10dc1a2016183a262ad3256bc468759Chris Lattnerextern int i5; // expected-note {{previous definition is here}}
27eaaebc7cf10dc1a2016183a262ad3256bc468759Chris Lattnerstatic int i5; // expected-error{{static declaration of 'i5' follows non-static declaration}}
28cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor
29275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregorstatic int i2 = 5; // expected-note 1 {{previous definition is here}}
3038179b29df101e3f55dbdff4d15d4d55cd82e2bdDouglas Gregorint i2 = 3; // expected-error{{non-static declaration of 'i2' follows static declaration}}
3138179b29df101e3f55dbdff4d15d4d55cd82e2bdDouglas Gregor
3238179b29df101e3f55dbdff4d15d4d55cd82e2bdDouglas Gregorstatic int i3 = 5;
3338179b29df101e3f55dbdff4d15d4d55cd82e2bdDouglas Gregorextern int i3;
34b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroff
354cc83c2b0aed5ab06081ea3250426c3a7e58df93Fariborz Jahanian// rdar://7703982
36767a1a2391e60e358ed7d793e091cc1731a5e186Fariborz Jahanian__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}} \
37767a1a2391e60e358ed7d793e091cc1731a5e186Fariborz Jahanian// expected-note {{use __attribute__((visibility("hidden"))) attribute instead}}
38235549c7bda856c26cff68190860f69760fa576dSteve Naroffint pExtern = 0;
39235549c7bda856c26cff68190860f69760fa576dSteve Naroff
40ff9eb1fe0a16a34c355db0d1bc4a9d0f7a276c73Steve Naroffint i4;
41ff9eb1fe0a16a34c355db0d1bc4a9d0f7a276c73Steve Naroffint i4;
42ff9eb1fe0a16a34c355db0d1bc4a9d0f7a276c73Steve Naroffextern int i4;
43ff9eb1fe0a16a34c355db0d1bc4a9d0f7a276c73Steve Naroff
44907747b3a67a41420ead8ef1fc5e6bd9dc9e0ad9Steve Naroffint (*pToArray)[];
45907747b3a67a41420ead8ef1fc5e6bd9dc9e0ad9Steve Naroffint (*pToArray)[8];
46907747b3a67a41420ead8ef1fc5e6bd9dc9e0ad9Steve Naroff
47f855e6fbebb718a1cca75ec2efba12f3583fe614Steve Naroffint redef[10];
485f4a6829dc58cab2f76e2b98492859aa3b91e3f2Chris Lattnerint redef[];  // expected-note {{previous definition is here}}
49f855e6fbebb718a1cca75ec2efba12f3583fe614Steve Naroffint redef[11]; // expected-error{{redefinition of 'redef'}}
50f855e6fbebb718a1cca75ec2efba12f3583fe614Steve Naroff
51b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroffvoid func() {
52eaaebc7cf10dc1a2016183a262ad3256bc468759Chris Lattner  extern int i6; // expected-note {{previous definition is here}}
53eaaebc7cf10dc1a2016183a262ad3256bc468759Chris Lattner  static int i6; // expected-error{{static declaration of 'i6' follows non-static declaration}}
54b7b032ecb23e5a2ebff89d62478f93313c04d367Steve Naroff}
55094cefbcc48c6b29062fef343fa8ff78ad368713Steve Naroff
56094cefbcc48c6b29062fef343fa8ff78ad368713Steve Naroffvoid func2(void)
57094cefbcc48c6b29062fef343fa8ff78ad368713Steve Naroff{
58094cefbcc48c6b29062fef343fa8ff78ad368713Steve Naroff  extern double *p;
59094cefbcc48c6b29062fef343fa8ff78ad368713Steve Naroff  extern double *p;
60094cefbcc48c6b29062fef343fa8ff78ad368713Steve Naroff}
61a03aca82de5259846d4ef38db11b8116398d2222Douglas Gregor
62b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor// <rdar://problem/6808352>
63b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregorstatic int a0[];
64b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregorstatic int b0;
65b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor
66b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregorstatic int a0[] = { 4 };
67b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregorstatic int b0 = 5;
68