blob: 62c6ff96ca9f428c92d3c952b8465570ad827246 [file] [log] [blame]
John McCall15e310a2011-02-19 02:53:41 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3// Make sure we don't produce invalid IR.
4// RUN: %clang_cc1 -emit-llvm-only %s
5
6namespace test1 {
7 static void foo(); // expected-warning {{function 'test1::foo' has internal linkage but is not defined}}
8 template <class T> static void bar(); // expected-warning {{function 'test1::bar<int>' has internal linkage but is not defined}}
9
10 void test() {
11 foo(); // expected-note {{used here}}
12 bar<int>(); // expected-note {{used here}}
13 }
14}
15
16namespace test2 {
17 namespace {
18 void foo(); // expected-warning {{function 'test2::<anonymous namespace>::foo' has internal linkage but is not defined}}
19 extern int var; // expected-warning {{variable 'test2::<anonymous namespace>::var' has internal linkage but is not defined}}
20 template <class T> void bar(); // expected-warning {{function 'test2::<anonymous namespace>::bar<int>' has internal linkage but is not defined}}
21 }
22 void test() {
23 foo(); // expected-note {{used here}}
24 var = 0; // expected-note {{used here}}
25 bar<int>(); // expected-note {{used here}}
26 }
27}
28
29namespace test3 {
30 namespace {
31 void foo();
32 extern int var;
33 template <class T> void bar();
34 }
35
36 void test() {
37 foo();
38 var = 0;
39 bar<int>();
40 }
41
42 namespace {
43 void foo() {}
44 int var = 0;
45 template <class T> void bar() {}
46 }
47}
48
49namespace test4 {
50 namespace {
51 struct A {
52 A(); // expected-warning {{function 'test4::<anonymous namespace>::A::A' has internal linkage but is not defined}}
53 ~A();// expected-warning {{function 'test4::<anonymous namespace>::A::~A' has internal linkage but is not defined}}
54 virtual void foo(); // expected-warning {{function 'test4::<anonymous namespace>::A::foo' has internal linkage but is not defined}}
55 virtual void bar() = 0;
56 virtual void baz(); // expected-warning {{function 'test4::<anonymous namespace>::A::baz' has internal linkage but is not defined}}
57 };
58 }
59
60 void test(A &a) {
61 a.foo(); // expected-note {{used here}}
62 a.bar();
63 a.baz(); // expected-note {{used here}}
64 }
65
66 struct Test : A {
67 Test() {} // expected-note 2 {{used here}}
68 };
69}
70
71// rdar://problem/9014651
72namespace test5 {
73 namespace {
74 struct A {};
75 }
76
77 template <class N> struct B {
78 static int var; // expected-warning {{variable 'test5::B<test5::<anonymous>::A>::var' has internal linkage but is not defined}}
79 static void foo(); // expected-warning {{function 'test5::B<test5::<anonymous>::A>::foo' has internal linkage but is not defined}}
80 };
81
82 void test() {
83 B<A>::var = 0; // expected-note {{used here}}
84 B<A>::foo(); // expected-note {{used here}}
85 }
86}
John McCall77efc682011-02-21 19:25:48 +000087
88namespace test6 {
89 template <class T> struct A {
90 static const int zero = 0;
91 static const int one = 1;
92 static const int two = 2;
93
94 int value;
95
96 A() : value(zero) {
97 value = one;
98 }
99 };
100
101 namespace { struct Internal; }
102
103 void test() {
104 A<Internal> a;
105 a.value = A<Internal>::two;
106 }
107}
Chandler Carruth30028232011-02-25 08:52:25 +0000108
109// We support (as an extension) private, undefined copy constructors when
110// a temporary is bound to a reference even in C++98. Similarly, we shouldn't
111// warn about this copy constructor being used without a definition.
112namespace PR9323 {
113 namespace {
114 struct Uncopyable {
115 Uncopyable() {}
116 private:
117 Uncopyable(const Uncopyable&); // expected-note {{declared private here}}
118 };
119 }
120 void f(const Uncopyable&) {}
121 void test() {
122 f(Uncopyable()); // expected-warning {{C++98 requires an accessible copy constructor}}
123 };
124}
Eli Friedmand2cce132012-02-02 23:15:15 +0000125
126
127namespace std { class type_info; };
128namespace cxx11_odr_rules {
129 // Note: the way this test is written isn't really ideal, but there really
130 // isn't any other way to check that the odr-used logic for constants
131 // is working without working implicit capture in lambda-expressions.
132 // (The more accurate used-but-not-defined warning is the only other visible
133 // effect of accurate odr-used computation.)
134 //
135 // Note that the warning in question can trigger in cases some people would
136 // consider false positives; hopefully that happens rarely in practice.
Eli Friedman0cc5d402012-02-04 00:54:05 +0000137 //
138 // FIXME: Suppressing this test while I figure out how to fix a bug in the
139 // odr-use marking code.
Eli Friedmand2cce132012-02-02 23:15:15 +0000140
141 namespace {
142 struct A {
143 static const int unused = 10;
Eli Friedman0cc5d402012-02-04 00:54:05 +0000144 static const int used1 = 20; // xpected-warning {{internal linkage}}
145 static const int used2 = 20; // xpected-warning {{internal linkage}}
Eli Friedmand2cce132012-02-02 23:15:15 +0000146 virtual ~A() {}
147 };
148 }
149
150 void a(int,int);
151 A& p(const int&) { static A a; return a; }
152
153 // Check handling of default arguments
154 void b(int = A::unused);
155
156 void tests() {
157 // Basic test
158 a(A::unused, A::unused);
159
160 // Check that nesting an unevaluated or constant-evaluated context does
161 // the right thing.
162 a(A::unused, sizeof(int[10]));
163
164 // Check that the checks work with unevaluated contexts
165 (void)sizeof(p(A::used1));
Eli Friedman0cc5d402012-02-04 00:54:05 +0000166 (void)typeid(p(A::used1)); // xpected-note {{used here}}
Eli Friedmand2cce132012-02-02 23:15:15 +0000167
168 // Misc other testing
Eli Friedman0cc5d402012-02-04 00:54:05 +0000169 a(A::unused, 1 ? A::used2 : A::used2); // xpected-note {{used here}}
Eli Friedmand2cce132012-02-02 23:15:15 +0000170 b();
171 }
172}
Eli Friedman59a839c2012-02-08 03:07:05 +0000173
174
175namespace OverloadUse {
176 namespace {
177 void f();
178 void f(int); // expected-warning {{function 'OverloadUse::<anonymous namespace>::f' has internal linkage but is not defined}}
179 }
180 template<void x()> void t(int*) { x(); }
181 template<void x(int)> void t(long*) { x(10); } // expected-note {{used here}}
182 void g() { long a; t<f>(&a); }
183}
Rafael Espindola9f409542012-12-29 23:43:00 +0000184
185namespace test7 {
186 typedef struct {
187 void bar();
188 void foo() {
189 bar();
190 }
191 } A;
192}
193
194namespace test8 {
195 typedef struct {
196 void bar(); // expected-warning {{function 'test8::<anonymous struct>::bar' has internal linkage but is not defined}}
197 void foo() {
198 bar(); // expected-note {{used here}}
199 }
200 } *A;
201}
Nick Lewycky4ceaf332013-01-31 01:34:31 +0000202
203namespace test9 {
204 namespace {
205 struct X {
206 virtual void notused() = 0;
207 virtual void used() = 0; // expected-warning {{function 'test9::<anonymous namespace>::X::used' has internal linkage but is not defined}}
208 };
209 }
210 void test(X &x) {
211 x.notused();
212 x.X::used(); // expected-note {{used here}}
213 }
214}