1 // RUN: %clang_cc1 -fsyntax-only -verify %s
15 extern int test2_x; // expected-note {{declared with C language linkage here}}
19 float test2_x; // expected-error {{declaration of 'test2_x' in global scope conflicts with declaration with C language linkage}}
24 extern int test3_b; // expected-note {{previous declaration is here}}
28 float test3_b; // expected-error {{redefinition of 'test3_b' with a different type: 'float' vs 'int'}}
35 extern int test4_b; // expected-note {{declared with C language linkage here}}
39 static float test4_b; // expected-error {{declaration of 'test4_b' in global scope conflicts with declaration with C language linkage}}
43 extern int test4_c; // expected-note {{previous}}
46 static float test4_c; // expected-error {{redefinition of 'test4_c' with a different type: 'float' vs 'int'}}
51 extern int test5_b; // expected-note {{declared with C language linkage here}}
56 static float test5_b; // expected-error {{declaration of 'test5_b' in global scope conflicts with declaration with C language linkage}}
61 extern int test5_c; // expected-note {{previous}}
65 static float test5_c; // expected-error {{redefinition of 'test5_c' with a different type: 'float' vs 'int'}}
83 static void linkage_redecl();
84 static void linkage_redecl(int);
85 void linkage_redecl(); // ok, still not extern "C"
86 void linkage_redecl(int); // ok, still not extern "C"
87 void linkage_redecl(float); // expected-note {{previous}}
88 void linkage_redecl(double); // expected-error {{conflicting types}}
91 namespace from_outer {
92 void linkage_from_outer_1(); // expected-note {{previous}}
93 void linkage_from_outer_2(); // expected-note {{previous}}
95 void linkage_from_outer_1(int);
96 void linkage_from_outer_1(); // expected-error {{different language linkage}}
97 void linkage_from_outer_2(); // expected-error {{different language linkage}}
102 void linkage_mixed_1();
103 static void linkage_mixed_1(int);
105 static void linkage_mixed_2(int);
106 void linkage_mixed_2();
109 namespace across_scopes {
111 extern "C" void linkage_across_scopes_f() {
112 void linkage_across_scopes_g(); // expected-note {{previous}}
116 extern "C" void linkage_across_scopes_g(int); // expected-error {{conflicting}}
121 int lookup_in_global_f; // expected-note {{here}}
122 namespace lookup_in_global {
123 void lookup_in_global_f();
124 void lookup_in_global_g();
126 void lookup_in_global_f(int); // expected-error {{conflicts with declaration in global scope}}
127 void lookup_in_global_g(int); // expected-note {{here}}
130 int lookup_in_global_g; // expected-error {{conflicts with declaration with C language linkage}}
133 extern "C" int different_kind_1; // expected-note {{here}}
134 extern "C" void different_kind_2(); // expected-note {{here}}
137 extern "C" void different_kind_1(); // expected-error {{different kind of symbol}}
138 extern "C" int different_kind_2; // expected-error {{different kind of symbol}}
141 // We allow all these even though the standard says they are ill-formed.
143 struct stat {}; // expected-warning{{empty struct has size 0 in C, size 1 in C++}}
144 void stat(struct stat);
148 void stat(struct ::stat);
152 void global_fn_vs_extern_c_var_1();
154 extern "C" int global_fn_vs_extern_c_var_1;
155 extern "C" int global_fn_vs_extern_c_var_2;
157 void global_fn_vs_extern_c_var_2();
158 void global_fn_vs_extern_c_fn_1();
160 extern "C" int global_fn_vs_extern_c_fn_1(int);
161 extern "C" int global_fn_vs_extern_c_fn_2(int);
163 void global_fn_vs_extern_c_fn_2();
164 extern "C" void name_with_using_decl_1(int);
165 namespace using_decl {
166 void name_with_using_decl_1();
167 void name_with_using_decl_2();
168 void name_with_using_decl_3();
170 using using_decl::name_with_using_decl_1;
171 using using_decl::name_with_using_decl_2;
172 extern "C" void name_with_using_decl_2(int);
173 extern "C" void name_with_using_decl_3(int);
174 using using_decl::name_with_using_decl_3;
176 // We do not allow a global variable and an extern "C" function to have the same
177 // name, because such entities may have the same mangled name.
178 int global_var_vs_extern_c_fn_1; // expected-note {{here}}
180 extern "C" void global_var_vs_extern_c_fn_1(); // expected-error {{conflicts with declaration in global scope}}
181 extern "C" void global_var_vs_extern_c_fn_2(); // expected-note {{here}}
183 int global_var_vs_extern_c_fn_2; // expected-error {{conflicts with declaration with C language linkage}}
184 int global_var_vs_extern_c_var_1; // expected-note {{here}}
186 extern "C" double global_var_vs_extern_c_var_1; // expected-error {{conflicts with declaration in global scope}}
187 extern "C" double global_var_vs_extern_c_var_2; // expected-note {{here}}
189 int global_var_vs_extern_c_var_2; // expected-error {{conflicts with declaration with C language linkage}}
191 template <class T> struct pr5065_n1 {};
193 union pr5065_1 {}; // expected-warning{{empty union has size 0 in C, size 1 in C++}}
194 struct pr5065_2 { int: 0; }; // expected-warning{{struct has size 0 in C, size 1 in C++}}
195 struct pr5065_3 {}; // expected-warning{{empty struct has size 0 in C, size 1 in C++}}
196 struct pr5065_4 { // expected-warning{{empty struct has size 0 in C, size 1 in C++}}
197 struct Inner {}; // expected-warning{{empty struct has size 0 in C, size 1 in C++}}
199 // These should not warn
201 pr5065_n1<int> pr5065_v;
202 struct pr5065_n4 { void m() {} };
203 struct pr5065_n5 : public pr5065_3 {};
204 struct pr5065_n6 : public virtual pr5065_3 {};