blob: aa2b2e5103cb6e92f55c8a68ab79e834acefaf6d [file] [log] [blame]
Rafael Espindolad2ecc132013-01-03 04:29:20 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-c++11-extensions -std=c++98 %s
Richard Smith27501e72012-10-28 04:47:21 +00002// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -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
35#else
36#define HEADER
37#include "warn-unused-filescoped.cpp"
38
Argyrios Kyrtzidis1b30d9c2010-08-15 01:15:20 +000039static void f1(); // expected-warning{{unused}}
40
41namespace {
42 void f2(); // expected-warning{{unused}}
43
44 void f3() { } // expected-warning{{unused}}
45
46 struct S {
47 void m1() { } // expected-warning{{unused}}
48 void m2(); // expected-warning{{unused}}
49 void m3();
Argyrios Kyrtzidis04c7fa02010-08-15 10:17:33 +000050 S(const S&);
51 void operator=(const S&);
Argyrios Kyrtzidis1b30d9c2010-08-15 01:15:20 +000052 };
53
54 template <typename T>
55 struct TS {
56 void m();
57 };
58 template <> void TS<int>::m() { } // expected-warning{{unused}}
59
60 template <typename T>
61 void tf() { }
62 template <> void tf<int>() { } // expected-warning{{unused}}
63
64 struct VS {
65 virtual void vm() { }
66 };
67
68 struct SVS : public VS {
69 void vm() { }
70 };
71}
72
73void S::m3() { } // expected-warning{{unused}}
74
Eli Friedman5ef21752013-09-10 03:05:56 +000075static inline void f4() { } // expected-warning{{unused}}
76const unsigned int cx = 0; // expected-warning{{unused}}
77const unsigned int cy = 0;
78int f5() { return cy; }
Argyrios Kyrtzidis1b30d9c2010-08-15 01:15:20 +000079
80static int x1; // expected-warning{{unused}}
81
82namespace {
83 int x2; // expected-warning{{unused}}
84
85 struct S2 {
86 static int x; // expected-warning{{unused}}
87 };
88
89 template <typename T>
90 struct TS2 {
91 static int x;
92 };
93 template <> int TS2<int>::x; // expected-warning{{unused}}
94}
Chandler Carruth8e666512011-01-03 19:27:19 +000095
96namespace PR8841 {
97 // Ensure that friends of class templates are considered to have a dependent
98 // context and not marked unused.
99 namespace {
100 template <typename T> struct X {
101 friend bool operator==(const X&, const X&) { return false; }
102 };
103 }
104 template <typename T> void template_test(X<T> x) {
105 (void)(x == x);
106 }
John McCallf768aa72011-02-10 06:50:24 +0000107 void test() {
108 X<int> x;
Chandler Carruth8e666512011-01-03 19:27:19 +0000109 template_test(x);
110 }
111}
John McCallf768aa72011-02-10 06:50:24 +0000112
113namespace test4 {
114 namespace { struct A {}; }
115
116 void test(A a); // expected-warning {{unused function}}
117 extern "C" void test4(A a);
118}
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000119
120namespace rdar8733476 {
121 static void foo() { } // expected-warning {{not needed and will not be emitted}}
122
123 template <int>
124 void bar() {
125 foo();
126 }
127}
Richard Smith27501e72012-10-28 04:47:21 +0000128
129namespace test5 {
130 static int n = 0;
131 static int &r = n;
132 int f(int &);
133 int k = f(r);
134
Richard Smith59a8e492012-10-28 07:39:29 +0000135 // FIXME: We should produce warnings for both of these.
136 static const int m = n;
Richard Smith27501e72012-10-28 04:47:21 +0000137 int x = sizeof(m);
Eli Friedman5ef21752013-09-10 03:05:56 +0000138 static const double d = 0.0; // expected-warning{{not needed and will not be emitted}}
Richard Smith27501e72012-10-28 04:47:21 +0000139 int y = sizeof(d);
140}
David Blaikie095deba2012-11-14 01:52:05 +0000141
142namespace unused_nested {
143 class outer {
144 void func1();
145 struct {
146 void func2() {
147 }
148 } x;
149 };
150}
151
152namespace unused {
153 struct {
154 void func() { // expected-warning {{unused member function}}
155 }
156 } x; // expected-warning {{unused variable}}
157}
Rafael Espindolaea7537f2012-12-30 21:42:26 +0000158
159namespace test6 {
160 typedef struct {
161 void bar();
162 } A;
163
164 typedef struct {
165 void bar(); // expected-warning {{unused member function 'bar'}}
166 } *B;
167
168 struct C {
169 void bar();
170 };
171}
Rafael Espindolad2ecc132013-01-03 04:29:20 +0000172
173namespace pr14776 {
174 namespace {
175 struct X {};
176 }
177 X a = X(); // expected-warning {{unused variable 'a'}}
178 auto b = X(); // expected-warning {{unused variable 'b'}}
179}
Eli Friedman5ef21752013-09-10 03:05:56 +0000180
181#endif