blob: 9fb601130d3b5e1da949dbbc56f1cdbb8032a675 [file] [log] [blame]
Rafael Espindola6769ccb2013-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 Smith623ef4b2012-10-28 04:47:21 +00002// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -std=c++11 %s
Argyrios Kyrtzidisbbc64542010-08-15 01:15:20 +00003
4static void f1(); // expected-warning{{unused}}
5
6namespace {
7 void f2(); // expected-warning{{unused}}
8
9 void f3() { } // expected-warning{{unused}}
10
11 struct S {
12 void m1() { } // expected-warning{{unused}}
13 void m2(); // expected-warning{{unused}}
14 void m3();
Argyrios Kyrtzidis06999f82010-08-15 10:17:33 +000015 S(const S&);
16 void operator=(const S&);
Argyrios Kyrtzidisbbc64542010-08-15 01:15:20 +000017 };
18
19 template <typename T>
20 struct TS {
21 void m();
22 };
23 template <> void TS<int>::m() { } // expected-warning{{unused}}
24
25 template <typename T>
26 void tf() { }
27 template <> void tf<int>() { } // expected-warning{{unused}}
28
29 struct VS {
30 virtual void vm() { }
31 };
32
33 struct SVS : public VS {
34 void vm() { }
35 };
36}
37
38void S::m3() { } // expected-warning{{unused}}
39
40static inline void f4() { }
41const unsigned int cx = 0;
42
43static int x1; // expected-warning{{unused}}
44
45namespace {
46 int x2; // expected-warning{{unused}}
47
48 struct S2 {
49 static int x; // expected-warning{{unused}}
50 };
51
52 template <typename T>
53 struct TS2 {
54 static int x;
55 };
56 template <> int TS2<int>::x; // expected-warning{{unused}}
57}
Chandler Carruthef9d09c2011-01-03 19:27:19 +000058
59namespace PR8841 {
60 // Ensure that friends of class templates are considered to have a dependent
61 // context and not marked unused.
62 namespace {
63 template <typename T> struct X {
64 friend bool operator==(const X&, const X&) { return false; }
65 };
66 }
67 template <typename T> void template_test(X<T> x) {
68 (void)(x == x);
69 }
John McCallaf8ca372011-02-10 06:50:24 +000070 void test() {
71 X<int> x;
Chandler Carruthef9d09c2011-01-03 19:27:19 +000072 template_test(x);
73 }
74}
John McCallaf8ca372011-02-10 06:50:24 +000075
76namespace test4 {
77 namespace { struct A {}; }
78
79 void test(A a); // expected-warning {{unused function}}
80 extern "C" void test4(A a);
81}
Argyrios Kyrtzidis6b6b42a2011-04-19 19:51:10 +000082
83namespace rdar8733476 {
84 static void foo() { } // expected-warning {{not needed and will not be emitted}}
85
86 template <int>
87 void bar() {
88 foo();
89 }
90}
Richard Smith623ef4b2012-10-28 04:47:21 +000091
92namespace test5 {
93 static int n = 0;
94 static int &r = n;
95 int f(int &);
96 int k = f(r);
97
Richard Smithc36e3592012-10-28 07:39:29 +000098 // FIXME: We should produce warnings for both of these.
99 static const int m = n;
Richard Smith623ef4b2012-10-28 04:47:21 +0000100 int x = sizeof(m);
Richard Smithc36e3592012-10-28 07:39:29 +0000101 static const double d = 0.0;
Richard Smith623ef4b2012-10-28 04:47:21 +0000102 int y = sizeof(d);
103}
David Blaikie66cff722012-11-14 01:52:05 +0000104
105namespace unused_nested {
106 class outer {
107 void func1();
108 struct {
109 void func2() {
110 }
111 } x;
112 };
113}
114
115namespace unused {
116 struct {
117 void func() { // expected-warning {{unused member function}}
118 }
119 } x; // expected-warning {{unused variable}}
120}
Rafael Espindola87b81272012-12-30 21:42:26 +0000121
122namespace test6 {
123 typedef struct {
124 void bar();
125 } A;
126
127 typedef struct {
128 void bar(); // expected-warning {{unused member function 'bar'}}
129 } *B;
130
131 struct C {
132 void bar();
133 };
134}
Rafael Espindola6769ccb2013-01-03 04:29:20 +0000135
Rafael Espindola6ca67522013-04-16 15:21:30 +0000136namespace test7
137{
138 template<typename T>
139 static inline void foo(T) { }
140
141 // This should not emit an unused-function warning since it inherits
142 // the static storage type from the base template.
143 template<>
144 inline void foo(int) { }
145
146 // Partial specialization
147 template<typename T, typename U>
148 static inline void bar(T, U) { }
149
150 template<typename U>
151 inline void bar(int, U) { }
152
153 template<>
154 inline void bar(int, int) { }
155};
156
Rafael Espindola6769ccb2013-01-03 04:29:20 +0000157namespace pr14776 {
158 namespace {
159 struct X {};
160 }
161 X a = X(); // expected-warning {{unused variable 'a'}}
162 auto b = X(); // expected-warning {{unused variable 'b'}}
163}