1 // RUN: %clang_cc1 -fsyntax-only -verify %s 2 3 namespace test1 { 4 extern "C" { 5 void test1_f() { 6 void test1_g(int); 7 } 8 } 9 } 10 int test1_g(int); 11 12 namespace test2 { 13 extern "C" { 14 void test2_f() { 15 extern int test2_x; // expected-note {{declared with C language linkage here}} 16 } 17 } 18 } 19 float test2_x; // expected-error {{declaration of 'test2_x' in global scope conflicts with declaration with C language linkage}} 20 21 namespace test3 { 22 extern "C" { 23 void test3_f() { 24 extern int test3_b; // expected-note {{previous definition is here}} 25 } 26 } 27 extern "C" { 28 float test3_b; // expected-error {{redefinition of 'test3_b' with a different type: 'float' vs 'int'}} 29 } 30 } 31 32 extern "C" { 33 void test4_f() { 34 extern int test4_b; // expected-note {{declared with C language linkage here}} 35 } 36 } 37 static float test4_b; // expected-error {{declaration of 'test4_b' in global scope conflicts with declaration with C language linkage}} 38 39 extern "C" { 40 void test5_f() { 41 extern int test5_b; // expected-note {{declared with C language linkage here}} 42 } 43 } 44 extern "C" { 45 static float test5_b; // expected-error {{declaration of 'test5_b' in global scope conflicts with declaration with C language linkage}} 46 } 47 48 extern "C" { 49 void f() { 50 extern int test6_b; 51 } 52 } 53 namespace foo { 54 extern "C" { 55 static float test6_b; 56 extern float test6_b; 57 } 58 } 59 60 namespace linkage { 61 namespace redecl { 62 extern "C" { 63 static void linkage_redecl(); 64 static void linkage_redecl(int); 65 void linkage_redecl(); // ok, still not extern "C" 66 void linkage_redecl(int); // ok, still not extern "C" 67 void linkage_redecl(float); // expected-note {{previous}} 68 void linkage_redecl(double); // expected-error {{conflicting types}} 69 } 70 } 71 namespace from_outer { 72 void linkage_from_outer_1(); // expected-note {{previous}} 73 void linkage_from_outer_2(); // expected-note {{previous}} 74 extern "C" { 75 void linkage_from_outer_1(int); 76 void linkage_from_outer_1(); // expected-error {{different language linkage}} 77 void linkage_from_outer_2(); // expected-error {{different language linkage}} 78 } 79 } 80 namespace mixed { 81 extern "C" { 82 void linkage_mixed_1(); 83 static void linkage_mixed_1(int); 84 85 static void linkage_mixed_2(int); 86 void linkage_mixed_2(); 87 } 88 } 89 namespace across_scopes { 90 namespace X { 91 extern "C" void linkage_across_scopes_f() { 92 void linkage_across_scopes_g(); // expected-note {{previous}} 93 } 94 } 95 namespace Y { 96 extern "C" void linkage_across_scopes_g(int); // expected-error {{conflicting}} 97 } 98 } 99 } 100 101 int lookup_in_global_f; // expected-note {{here}} 102 namespace lookup_in_global { 103 void lookup_in_global_f(); 104 void lookup_in_global_g(); 105 extern "C" { 106 void lookup_in_global_f(int); // expected-error {{conflicts with declaration in global scope}} 107 void lookup_in_global_g(int); // expected-note {{here}} 108 } 109 } 110 int lookup_in_global_g; // expected-error {{conflicts with declaration with C language linkage}} 111 112 namespace N1 { 113 extern "C" int different_kind_1; // expected-note {{here}} 114 extern "C" void different_kind_2(); // expected-note {{here}} 115 } 116 namespace N2 { 117 extern "C" void different_kind_1(); // expected-error {{different kind of symbol}} 118 extern "C" int different_kind_2; // expected-error {{different kind of symbol}} 119 } 120 121 // We allow all these even though the standard says they are ill-formed. 122 extern "C" { 123 struct stat {}; 124 void stat(struct stat); 125 } 126 namespace X { 127 extern "C" { 128 void stat(struct ::stat); 129 } 130 } 131 int stat(int *p); 132 void global_fn_vs_extern_c_var_1(); 133 namespace X { 134 extern "C" int global_fn_vs_extern_c_var_1; 135 extern "C" int global_fn_vs_extern_c_var_2; 136 } 137 void global_fn_vs_extern_c_var_2(); 138 void global_fn_vs_extern_c_fn_1(); 139 namespace X { 140 extern "C" int global_fn_vs_extern_c_fn_1(int); 141 extern "C" int global_fn_vs_extern_c_fn_2(int); 142 } 143 void global_fn_vs_extern_c_fn_2(); 144 extern "C" void name_with_using_decl_1(int); 145 namespace using_decl { 146 void name_with_using_decl_1(); 147 void name_with_using_decl_2(); 148 void name_with_using_decl_3(); 149 } 150 using using_decl::name_with_using_decl_1; 151 using using_decl::name_with_using_decl_2; 152 extern "C" void name_with_using_decl_2(int); 153 extern "C" void name_with_using_decl_3(int); 154 using using_decl::name_with_using_decl_3; 155 156 // We do not allow a global variable and an extern "C" function to have the same 157 // name, because such entities may have the same mangled name. 158 int global_var_vs_extern_c_fn_1; // expected-note {{here}} 159 namespace X { 160 extern "C" void global_var_vs_extern_c_fn_1(); // expected-error {{conflicts with declaration in global scope}} 161 extern "C" void global_var_vs_extern_c_fn_2(); // expected-note {{here}} 162 } 163 int global_var_vs_extern_c_fn_2; // expected-error {{conflicts with declaration with C language linkage}} 164 int global_var_vs_extern_c_var_1; // expected-note {{here}} 165 namespace X { 166 extern "C" double global_var_vs_extern_c_var_1; // expected-error {{conflicts with declaration in global scope}} 167 extern "C" double global_var_vs_extern_c_var_2; // expected-note {{here}} 168 } 169 int global_var_vs_extern_c_var_2; // expected-error {{conflicts with declaration with C language linkage}} 170