blob: 1598d0e35a050b1663099e12cd8350dd2b7887b5 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Alp Tokera8a2ebe2013-10-22 22:53:01 +00002// RUN: %clang_cc1 -fsyntax-only -verify -Wretained-language-linkage -DW_RETAINED_LANGUAGE_LINKAGE %s
Douglas Gregor6c6fce02009-01-05 19:50:09 +00003extern "C" {
4 extern "C" void f(int);
5}
6
7extern "C++" {
8 extern "C++" int& g(int);
9 float& g();
10}
11double& g(double);
12
13void test(int x, double d) {
14 f(x);
15 float &f1 = g();
16 int& i1 = g(x);
17 double& d1 = g(d);
18}
Douglas Gregor17a9b9e2009-01-07 02:48:43 +000019
20extern "C" int foo;
21extern "C" int foo;
22
23extern "C" const int bar;
24extern "C" int const bar;
Anders Carlsson425bfde2009-05-16 22:05:23 +000025
26// <rdar://problem/6895431>
27extern "C" struct bar d;
28extern struct bar e;
Douglas Gregora24eb4e2009-08-24 18:55:03 +000029
30extern "C++" {
31 namespace N0 {
32 struct X0 {
33 int foo(int x) { return x; }
34 };
35 }
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000036}
Sebastian Redl9770ef02009-11-08 11:36:54 +000037
38// PR5430
39namespace pr5430 {
40 extern "C" void func(void);
41}
42using namespace pr5430;
43extern "C" void pr5430::func(void) { }
Douglas Gregor12372592009-12-08 15:38:36 +000044
Richard Smithaa4bc182013-06-30 09:48:50 +000045// PR5405
Timur Iskhodzhanov6e428a42013-06-29 08:38:42 +000046int f2(char *)
Douglas Gregor12372592009-12-08 15:38:36 +000047{
48 return 0;
49}
50
51extern "C"
52{
Timur Iskhodzhanov6e428a42013-06-29 08:38:42 +000053 int f2(int)
Douglas Gregor12372592009-12-08 15:38:36 +000054 {
55 return f2((char *)0);
56 }
57}
Abramo Bagnara35f9a192010-07-30 16:47:02 +000058
Richard Smithaa4bc182013-06-30 09:48:50 +000059namespace 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 Bagnara35f9a192010-07-30 16:47:02 +000071// PR6991
72extern "C" typedef int (*PutcFunc_t)(int);
John McCall7b492022010-08-12 07:09:11 +000073
74
75// PR7859
76extern "C" void pr7859_a(int) {} // expected-note {{previous definition}}
77extern "C" void pr7859_a(int) {} // expected-error {{redefinition}}
78
79extern "C" void pr7859_b() {} // expected-note {{previous definition}}
80extern "C" void pr7859_b(int) {} // expected-error {{conflicting}}
81
82extern "C" void pr7859_c(short) {} // expected-note {{previous definition}}
83extern "C" void pr7859_c(int) {} // expected-error {{conflicting}}
Douglas Gregor45975532010-08-17 16:09:23 +000084
85// <rdar://problem/8318976>
86extern "C" {
87 struct s0 {
88 private:
89 s0();
90 s0(const s0 &);
91 };
92}
Douglas Gregor09a63c92010-08-24 14:14:45 +000093
94//PR7754
95extern "C++" template <class T> int pr7754(T param);
96
97namespace N {
98 int value;
99}
100
101extern "C++" using N::value;
Douglas Gregor66c42d42010-10-15 01:21:46 +0000102
103// PR7076
104extern "C" const char *Version_string = "2.9";
Douglas Gregor6d0468b2011-10-09 22:57:49 +0000105
Rafael Espindolab6bead42013-03-29 07:02:31 +0000106extern "C" {
107 extern const char *Version_string2 = "2.9";
108}
109
Douglas Gregor6d0468b2011-10-09 22:57:49 +0000110namespace 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 Espindolab98cf792013-05-05 18:24:05 +0000122
123namespace pr14958 {
124 namespace js { extern int ObjectClass; }
125 extern "C" {
126 namespace js {}
127 }
128 int js::ObjectClass;
129}
David Majnemeraa715672013-05-29 00:56:45 +0000130
131extern "C" void PR16167; // expected-error {{variable has incomplete type 'void'}}
David Majnemera3813c92013-05-31 21:29:50 +0000132extern void PR16167_0; // expected-error {{variable has incomplete type 'void'}}
Richard Smithaa4bc182013-06-30 09:48:50 +0000133
134// PR7927
135enum T_7927 {
136 E_7927
137};
138
139extern "C" void f_pr7927(int);
140
141namespace {
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
152void bar_pr7927() {
153 f_pr7927(E_7927);
154 f_pr7927(0);
155 ::f_pr7927(E_7927);
156 ::f_pr7927(0);
157}
Alp Tokera8a2ebe2013-10-22 22:53:01 +0000158
159namespace 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}