annotate clang/test/SemaCXX/linkage-spec.cpp @ 222:81f6424ef0e3 llvm-original

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