1 // RUN: %clang_cc1 -fsyntax-only -verify %s 2 3 namespace test1 { 4 int x; // expected-note {{previous definition is here}} 5 static int y; f()6 void f() {} // expected-note {{previous definition is here}} 7 8 extern "C" { 9 extern int x; // expected-error {{declaration of 'x' has a different language linkage}} 10 extern int y; // OK, has internal linkage, so no language linkage. 11 void f(); // expected-error {{declaration of 'f' has a different language linkage}} 12 } 13 } 14 15 // This is OK. Both test2_f don't have language linkage since they have 16 // internal linkage. 17 extern "C" { test2_f()18 static void test2_f() { 19 } test2_f(int x)20 static void test2_f(int x) { 21 } 22 } 23 24 namespace test3 { 25 extern "C" { 26 namespace { 27 extern int x2; 28 void f2(); 29 } 30 } 31 namespace { 32 int x2; f2()33 void f2() {} 34 } 35 } 36 37 namespace test4 { dummy()38 void dummy() { 39 void Bar(); 40 class A { 41 friend void Bar(); 42 }; 43 } 44 } 45 46 namespace test5 { 47 static void g(); f()48 void f() 49 { 50 void g(); 51 } 52 } 53 54 // pr14898 55 namespace test6 { 56 template <class _Rp> 57 class __attribute__ ((__visibility__("default"))) shared_future; 58 template <class _Rp> 59 class future { 60 template <class> friend class shared_future; 61 shared_future<_Rp> share(); 62 }; 63 template <class _Rp> future<_Rp> 64 get_future(); 65 template <class _Rp> 66 struct shared_future<_Rp&> { 67 shared_future(future<_Rp&>&& __f); // expected-warning {{rvalue references are a C++11 extension}} 68 }; f()69 void f() { 70 typedef int T; 71 get_future<int>(); 72 typedef int& U; 73 shared_future<int&> f1 = get_future<int&>(); 74 } 75 } 76 77 // This is OK. The variables have internal linkage and therefore no language 78 // linkage. 79 extern "C" { 80 static int test7_x; 81 } 82 extern "C++" { 83 extern int test7_x; 84 } 85 extern "C++" { 86 static int test7_y; 87 } 88 extern "C" { 89 extern int test7_y; 90 } 91 extern "C" { typedef int test7_F(); static test7_F test7_f; } 92 extern "C++" { extern test7_F test7_f; } 93 94 // FIXME: This should be invalid. The function has no language linkage, but 95 // the function type has, so this is redeclaring the function with a different 96 // type. 97 extern "C++" { 98 static void test8_f(); 99 } 100 extern "C" { 101 extern void test8_f(); 102 } 103 extern "C" { 104 static void test8_g(); 105 } 106 extern "C++" { 107 extern void test8_g(); 108 } 109 110 extern "C" { 111 void __attribute__((overloadable)) test9_f(int c); // expected-note {{previous declaration is here}} 112 } 113 extern "C++" { 114 void __attribute__((overloadable)) test9_f(int c); // expected-error {{declaration of 'test9_f' has a different language linkage}} 115 } 116 117 extern "C" { 118 void __attribute__((overloadable)) test10_f(int); 119 void __attribute__((overloadable)) test10_f(double); 120 } 121 122 extern "C" { test11_f()123 void test11_f() { 124 void __attribute__((overloadable)) test11_g(int); 125 void __attribute__((overloadable)) test11_g(double); 126 } 127 } 128