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