1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -Wretained-language-linkage -DW_RETAINED_LANGUAGE_LINKAGE %s 3*f4a2713aSLionel Sambuc extern "C" { 4*f4a2713aSLionel Sambuc extern "C" void f(int); 5*f4a2713aSLionel Sambuc } 6*f4a2713aSLionel Sambuc 7*f4a2713aSLionel Sambuc extern "C++" { 8*f4a2713aSLionel Sambuc extern "C++" int& g(int); 9*f4a2713aSLionel Sambuc float& g(); 10*f4a2713aSLionel Sambuc } 11*f4a2713aSLionel Sambuc double& g(double); 12*f4a2713aSLionel Sambuc test(int x,double d)13*f4a2713aSLionel Sambucvoid test(int x, double d) { 14*f4a2713aSLionel Sambuc f(x); 15*f4a2713aSLionel Sambuc float &f1 = g(); 16*f4a2713aSLionel Sambuc int& i1 = g(x); 17*f4a2713aSLionel Sambuc double& d1 = g(d); 18*f4a2713aSLionel Sambuc } 19*f4a2713aSLionel Sambuc 20*f4a2713aSLionel Sambuc extern "C" int foo; 21*f4a2713aSLionel Sambuc extern "C" int foo; 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc extern "C" const int bar; 24*f4a2713aSLionel Sambuc extern "C" int const bar; 25*f4a2713aSLionel Sambuc 26*f4a2713aSLionel Sambuc // <rdar://problem/6895431> 27*f4a2713aSLionel Sambuc extern "C" struct bar d; 28*f4a2713aSLionel Sambuc extern struct bar e; 29*f4a2713aSLionel Sambuc 30*f4a2713aSLionel Sambuc extern "C++" { 31*f4a2713aSLionel Sambuc namespace N0 { 32*f4a2713aSLionel Sambuc struct X0 { fooN0::X033*f4a2713aSLionel Sambuc int foo(int x) { return x; } 34*f4a2713aSLionel Sambuc }; 35*f4a2713aSLionel Sambuc } 36*f4a2713aSLionel Sambuc } 37*f4a2713aSLionel Sambuc 38*f4a2713aSLionel Sambuc // PR5430 39*f4a2713aSLionel Sambuc namespace pr5430 { 40*f4a2713aSLionel Sambuc extern "C" void func(void); 41*f4a2713aSLionel Sambuc } 42*f4a2713aSLionel Sambuc using namespace pr5430; func(void)43*f4a2713aSLionel Sambucextern "C" void pr5430::func(void) { } 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc // PR5405 f2(char *)46*f4a2713aSLionel Sambucint f2(char *) 47*f4a2713aSLionel Sambuc { 48*f4a2713aSLionel Sambuc return 0; 49*f4a2713aSLionel Sambuc } 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambuc extern "C" 52*f4a2713aSLionel Sambuc { f2(int)53*f4a2713aSLionel Sambuc int f2(int) 54*f4a2713aSLionel Sambuc { 55*f4a2713aSLionel Sambuc return f2((char *)0); 56*f4a2713aSLionel Sambuc } 57*f4a2713aSLionel Sambuc } 58*f4a2713aSLionel Sambuc 59*f4a2713aSLionel Sambuc namespace PR5405 { f2b(char *)60*f4a2713aSLionel Sambuc int f2b(char *) { 61*f4a2713aSLionel Sambuc return 0; 62*f4a2713aSLionel Sambuc } 63*f4a2713aSLionel Sambuc 64*f4a2713aSLionel Sambuc extern "C" { f2b(int)65*f4a2713aSLionel Sambuc int f2b(int) { 66*f4a2713aSLionel Sambuc return f2b((char *)0); // ok 67*f4a2713aSLionel Sambuc } 68*f4a2713aSLionel Sambuc } 69*f4a2713aSLionel Sambuc } 70*f4a2713aSLionel Sambuc 71*f4a2713aSLionel Sambuc // PR6991 72*f4a2713aSLionel Sambuc extern "C" typedef int (*PutcFunc_t)(int); 73*f4a2713aSLionel Sambuc 74*f4a2713aSLionel Sambuc 75*f4a2713aSLionel Sambuc // PR7859 pr7859_a(int)76*f4a2713aSLionel Sambucextern "C" void pr7859_a(int) {} // expected-note {{previous definition}} pr7859_a(int)77*f4a2713aSLionel Sambucextern "C" void pr7859_a(int) {} // expected-error {{redefinition}} 78*f4a2713aSLionel Sambuc pr7859_b()79*f4a2713aSLionel Sambucextern "C" void pr7859_b() {} // expected-note {{previous definition}} pr7859_b(int)80*f4a2713aSLionel Sambucextern "C" void pr7859_b(int) {} // expected-error {{conflicting}} 81*f4a2713aSLionel Sambuc pr7859_c(short)82*f4a2713aSLionel Sambucextern "C" void pr7859_c(short) {} // expected-note {{previous definition}} pr7859_c(int)83*f4a2713aSLionel Sambucextern "C" void pr7859_c(int) {} // expected-error {{conflicting}} 84*f4a2713aSLionel Sambuc 85*f4a2713aSLionel Sambuc // <rdar://problem/8318976> 86*f4a2713aSLionel Sambuc extern "C" { 87*f4a2713aSLionel Sambuc struct s0 { 88*f4a2713aSLionel Sambuc private: 89*f4a2713aSLionel Sambuc s0(); 90*f4a2713aSLionel Sambuc s0(const s0 &); 91*f4a2713aSLionel Sambuc }; 92*f4a2713aSLionel Sambuc } 93*f4a2713aSLionel Sambuc 94*f4a2713aSLionel Sambuc //PR7754 95*f4a2713aSLionel Sambuc extern "C++" template <class T> int pr7754(T param); 96*f4a2713aSLionel Sambuc 97*f4a2713aSLionel Sambuc namespace N { 98*f4a2713aSLionel Sambuc int value; 99*f4a2713aSLionel Sambuc } 100*f4a2713aSLionel Sambuc 101*f4a2713aSLionel Sambuc extern "C++" using N::value; 102*f4a2713aSLionel Sambuc 103*f4a2713aSLionel Sambuc // PR7076 104*f4a2713aSLionel Sambuc extern "C" const char *Version_string = "2.9"; 105*f4a2713aSLionel Sambuc 106*f4a2713aSLionel Sambuc extern "C" { 107*f4a2713aSLionel Sambuc extern const char *Version_string2 = "2.9"; 108*f4a2713aSLionel Sambuc } 109*f4a2713aSLionel Sambuc 110*f4a2713aSLionel Sambuc namespace PR9162 { 111*f4a2713aSLionel Sambuc extern "C" { 112*f4a2713aSLionel Sambuc typedef struct _ArtsSink ArtsSink; 113*f4a2713aSLionel Sambuc struct _ArtsSink { 114*f4a2713aSLionel Sambuc int sink; 115*f4a2713aSLionel Sambuc }; 116*f4a2713aSLionel Sambuc } arts_sink_get_type()117*f4a2713aSLionel Sambuc int arts_sink_get_type() 118*f4a2713aSLionel Sambuc { 119*f4a2713aSLionel Sambuc return sizeof(ArtsSink); 120*f4a2713aSLionel Sambuc } 121*f4a2713aSLionel Sambuc } 122*f4a2713aSLionel Sambuc 123*f4a2713aSLionel Sambuc namespace pr14958 { 124*f4a2713aSLionel Sambuc namespace js { extern int ObjectClass; } 125*f4a2713aSLionel Sambuc extern "C" { 126*f4a2713aSLionel Sambuc namespace js {} 127*f4a2713aSLionel Sambuc } 128*f4a2713aSLionel Sambuc int js::ObjectClass; 129*f4a2713aSLionel Sambuc } 130*f4a2713aSLionel Sambuc 131*f4a2713aSLionel Sambuc extern "C" void PR16167; // expected-error {{variable has incomplete type 'void'}} 132*f4a2713aSLionel Sambuc extern void PR16167_0; // expected-error {{variable has incomplete type 'void'}} 133*f4a2713aSLionel Sambuc 134*f4a2713aSLionel Sambuc // PR7927 135*f4a2713aSLionel Sambuc enum T_7927 { 136*f4a2713aSLionel Sambuc E_7927 137*f4a2713aSLionel Sambuc }; 138*f4a2713aSLionel Sambuc 139*f4a2713aSLionel Sambuc extern "C" void f_pr7927(int); 140*f4a2713aSLionel Sambuc 141*f4a2713aSLionel Sambuc namespace { 142*f4a2713aSLionel Sambuc extern "C" void f_pr7927(int); 143*f4a2713aSLionel Sambuc foo_pr7927()144*f4a2713aSLionel Sambuc void foo_pr7927() { 145*f4a2713aSLionel Sambuc f_pr7927(E_7927); 146*f4a2713aSLionel Sambuc f_pr7927(0); 147*f4a2713aSLionel Sambuc ::f_pr7927(E_7927); 148*f4a2713aSLionel Sambuc ::f_pr7927(0); 149*f4a2713aSLionel Sambuc } 150*f4a2713aSLionel Sambuc } 151*f4a2713aSLionel Sambuc bar_pr7927()152*f4a2713aSLionel Sambucvoid bar_pr7927() { 153*f4a2713aSLionel Sambuc f_pr7927(E_7927); 154*f4a2713aSLionel Sambuc f_pr7927(0); 155*f4a2713aSLionel Sambuc ::f_pr7927(E_7927); 156*f4a2713aSLionel Sambuc ::f_pr7927(0); 157*f4a2713aSLionel Sambuc } 158*f4a2713aSLionel Sambuc 159*f4a2713aSLionel Sambuc namespace PR17337 { 160*f4a2713aSLionel Sambuc extern "C++" { 161*f4a2713aSLionel Sambuc class Foo; 162*f4a2713aSLionel Sambuc extern "C" int bar3(Foo *y); 163*f4a2713aSLionel Sambuc class Foo { 164*f4a2713aSLionel Sambuc int x; 165*f4a2713aSLionel Sambuc friend int bar3(Foo *y); 166*f4a2713aSLionel Sambuc #ifdef W_RETAINED_LANGUAGE_LINKAGE 167*f4a2713aSLionel Sambuc // expected-note@-5 {{previous declaration is here}} 168*f4a2713aSLionel Sambuc // expected-warning@-3 {{retaining previous language linkage}} 169*f4a2713aSLionel Sambuc #endif 170*f4a2713aSLionel Sambuc }; bar3(Foo * y)171*f4a2713aSLionel Sambuc extern "C" int bar3(Foo *y) { 172*f4a2713aSLionel Sambuc return y->x; 173*f4a2713aSLionel Sambuc } 174*f4a2713aSLionel Sambuc } 175*f4a2713aSLionel Sambuc } 176