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
{};
208 namespace tag_hiding
{
209 namespace namespace_with_injected_name
{
211 friend struct ExternCStruct1
;
213 void ExternCStruct4(); // expected-note 2{{candidate}}
217 friend struct ExternCStruct2
;
218 friend void ExternCStruct3();
221 using namespace namespace_with_injected_name
;
224 struct ExternCStruct1
;
225 struct ExternCStruct2
;
226 struct ExternCStruct3
;
227 struct ExternCStruct4
; // expected-note {{candidate}}
232 ExternCStruct4
*p4
; // expected-error {{ambiguous}}
235 struct ExternCStruct1
;
236 struct ExternCStruct2
;
237 struct ExternCStruct3
;
238 struct ExternCStruct4
; // expected-note {{candidate}}
240 ExternCStruct1
*q1
= p1
;
241 ExternCStruct2
*q2
= p2
;
242 ExternCStruct3
*q3
= p3
;
243 ExternCStruct4
*q4
= p4
; // expected-error {{ambiguous}}
247 typedef struct {} *ReturnStruct
;
248 extern "C" ReturnStruct
PR35697_f();
249 extern "C" ReturnStruct PR35697_v
;
250 ReturnStruct
PR35697_f();
251 ReturnStruct PR35697_v
;
254 extern "C" ReturnStruct
PR35697_f();
255 extern "C" ReturnStruct PR35697_v
;
257 extern ReturnStruct
PR35697_f();
258 extern ReturnStruct PR35697_v
;
264 extern "bogus" // expected-error {{unknown linkage language}}
265 template<int> struct X
{}; // expected-error {{templates can only be declared in namespace or class scope}}