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