blob: 18defee7d04a6fdb34d6ec964bbf808102defb7c [file] [log] [blame]
Nico Weber72889432014-09-06 01:25:55 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions -std=c++98 %s
2// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -std=c++11 %s
Argyrios Kyrtzidis1b30d9c2010-08-15 01:15:20 +00003
Eli Friedman5ef21752013-09-10 03:05:56 +00004#ifdef HEADER
5
6static void headerstatic() {} // expected-warning{{unused}}
7static inline void headerstaticinline() {}
8
9namespace {
10 void headeranon() {} // expected-warning{{unused}}
11 inline void headerinlineanon() {}
12}
13
14namespace test7
15{
16 template<typename T>
17 static inline void foo(T) { }
18
19 // This should not emit an unused-function warning since it inherits
20 // the static storage type from the base template.
21 template<>
22 inline void foo(int) { }
23
24 // Partial specialization
25 template<typename T, typename U>
26 static inline void bar(T, U) { }
27
28 template<typename U>
29 inline void bar(int, U) { }
30
31 template<>
32 inline void bar(int, int) { }
33};
34
Richard Smitha90ee352014-05-11 21:25:24 +000035namespace pr19713 {
36#if __cplusplus >= 201103L
37 static constexpr int constexpr1() { return 1; }
38 constexpr int constexpr2() { return 2; }
39#endif
40}
41
Eli Friedman5ef21752013-09-10 03:05:56 +000042#else
43#define HEADER
44#include "warn-unused-filescoped.cpp"
45
Argyrios Kyrtzidis1b30d9c2010-08-15 01:15:20 +000046static void f1(); // expected-warning{{unused}}
47
48namespace {
49 void f2(); // expected-warning{{unused}}
50
51 void f3() { } // expected-warning{{unused}}
52
53 struct S {
54 void m1() { } // expected-warning{{unused}}
55 void m2(); // expected-warning{{unused}}
56 void m3();
Argyrios Kyrtzidis04c7fa02010-08-15 10:17:33 +000057 S(const S&);
58 void operator=(const S&);
Argyrios Kyrtzidis1b30d9c2010-08-15 01:15:20 +000059 };
60
61 template <typename T>
62 struct TS {
63 void m();
64 };
65 template <> void TS<int>::m() { } // expected-warning{{unused}}
66
67 template <typename T>
68 void tf() { }
69 template <> void tf<int>() { } // expected-warning{{unused}}
70
71 struct VS {
72 virtual void vm() { }
73 };
74
75 struct SVS : public VS {
76 void vm() { }
77 };
78}
79
80void S::m3() { } // expected-warning{{unused}}
81
Eli Friedman5ef21752013-09-10 03:05:56 +000082static inline void f4() { } // expected-warning{{unused}}
83const unsigned int cx = 0; // expected-warning{{unused}}
84const unsigned int cy = 0;
85int f5() { return cy; }
Argyrios Kyrtzidis1b30d9c2010-08-15 01:15:20 +000086
87static int x1; // expected-warning{{unused}}
88
89namespace {
90 int x2; // expected-warning{{unused}}
91
92 struct S2 {
93 static int x; // expected-warning{{unused}}
94 };
95
96 template <typename T>
97 struct TS2 {
98 static int x;
99 };
100 template <> int TS2<int>::x; // expected-warning{{unused}}
101}
Chandler Carruth8e666512011-01-03 19:27:19 +0000102
103namespace PR8841 {
104 // Ensure that friends of class templates are considered to have a dependent
105 // context and not marked unused.
106 namespace {
107 template <typename T> struct X {
108 friend bool operator==(const X&, const X&) { return false; }
109 };
110 }
111 template <typename T> void template_test(X<T> x) {
112 (void)(x == x);
113 }
John McCallf768aa72011-02-10 06:50:24 +0000114 void test() {
115 X<int> x;
Chandler Carruth8e666512011-01-03 19:27:19 +0000116 template_test(x);
117 }
118}
John McCallf768aa72011-02-10 06:50:24 +0000119
120namespace test4 {
121 namespace { struct A {}; }
122
123 void test(A a); // expected-warning {{unused function}}
124 extern "C" void test4(A a);
125}
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000126
127namespace rdar8733476 {
128 static void foo() { } // expected-warning {{not needed and will not be emitted}}
129
130 template <int>
131 void bar() {
132 foo();
133 }
134}
Richard Smith27501e72012-10-28 04:47:21 +0000135
136namespace test5 {
137 static int n = 0;
138 static int &r = n;
139 int f(int &);
140 int k = f(r);
141
Richard Smith59a8e492012-10-28 07:39:29 +0000142 // FIXME: We should produce warnings for both of these.
143 static const int m = n;
Richard Smith27501e72012-10-28 04:47:21 +0000144 int x = sizeof(m);
Eli Friedman5ef21752013-09-10 03:05:56 +0000145 static const double d = 0.0; // expected-warning{{not needed and will not be emitted}}
Richard Smith27501e72012-10-28 04:47:21 +0000146 int y = sizeof(d);
147}
David Blaikie095deba2012-11-14 01:52:05 +0000148
149namespace unused_nested {
150 class outer {
151 void func1();
152 struct {
153 void func2() {
154 }
155 } x;
156 };
157}
158
159namespace unused {
160 struct {
161 void func() { // expected-warning {{unused member function}}
162 }
163 } x; // expected-warning {{unused variable}}
164}
Rafael Espindolaea7537f2012-12-30 21:42:26 +0000165
166namespace test6 {
167 typedef struct {
168 void bar();
169 } A;
170
171 typedef struct {
172 void bar(); // expected-warning {{unused member function 'bar'}}
173 } *B;
174
175 struct C {
176 void bar();
177 };
178}
Rafael Espindolad2ecc132013-01-03 04:29:20 +0000179
180namespace pr14776 {
181 namespace {
182 struct X {};
183 }
184 X a = X(); // expected-warning {{unused variable 'a'}}
185 auto b = X(); // expected-warning {{unused variable 'b'}}
186}
Eli Friedman5ef21752013-09-10 03:05:56 +0000187
Eli Friedmana5dfebd2013-09-10 21:10:25 +0000188namespace UndefinedInternalStaticMember {
189 namespace {
190 struct X {
191 static const unsigned x = 3;
192 int y[x];
193 };
194 }
195}
196
Rafael Espindolab0938852013-10-25 01:28:12 +0000197namespace test8 {
198static void func();
199void bar() { void func() __attribute__((used)); }
200static void func() {}
201}
202
Richard Smitha90ee352014-05-11 21:25:24 +0000203namespace pr19713 {
204#if __cplusplus >= 201103L
205 // FIXME: We should warn on both of these.
206 static constexpr int constexpr3() { return 1; } // expected-warning {{unused}}
207 constexpr int constexpr4() { return 2; }
208#endif
209}
210
Eli Friedman5ef21752013-09-10 03:05:56 +0000211#endif