1 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template -Wunused-member-function -Wno-unused-local-typedefs \
2 // RUN: -Wno-c++11-extensions -Wno-c++14-extensions -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template -Wunused-member-function -Wno-unused-local-typedefs -std=c++14 %s
7 static void headerstatic() {} // expected-warning{{unused function 'headerstatic'}}
8 static inline void headerstaticinline() {}
11 void headeranon() {} // expected-warning{{unused function 'headeranon'}}
12 inline void headerinlineanon() {}
18 static inline void foo(T
) { }
20 // This should not emit an unused-function warning since it inherits
21 // the static storage type from the base template.
23 inline void foo(int) { }
25 // Partial specialization
26 template<typename T
, typename U
>
27 static inline void bar(T
, U
) { }
30 inline void bar(int, U
) { }
33 inline void bar(int, int) { }
37 #if __cplusplus >= 201103L
38 static constexpr int constexpr1() { return 1; }
39 constexpr int constexpr2() { return 2; }
45 #include "warn-unused-filescoped.cpp"
47 static void f1(); // expected-warning{{unused function 'f1'}}
50 void f2(); // expected-warning{{unused function 'f2'}}
52 void f3() {} // expected-warning{{unused function 'f3'}}
55 void m1() {} // expected-warning{{unused member function 'm1'}}
56 void m2(); // expected-warning{{unused member function 'm2'}}
59 void operator=(const S
&);
66 template <> void TS
<int>::m() {} // expected-warning{{unused member function 'm'}}
69 void tf() {} // expected-warning{{unused function template 'tf'}}
70 template <> void tf
<int>() {} // expected-warning{{unused function 'tf<int>'}}
76 struct SVS
: public VS
{
81 void S::m3() {} // expected-warning{{unused member function 'm3'}}
83 static inline void f4() {} // expected-warning{{unused function 'f4'}}
84 const unsigned int cx
= 0; // expected-warning{{unused variable 'cx'}}
85 const unsigned int cy
= 0;
86 int f5() { return cy
; }
88 static int x1
; // expected-warning{{unused variable 'x1'}}
91 int x2
; // expected-warning{{unused variable 'x2'}}
94 static int x
; // expected-warning{{unused variable 'x'}}
101 template <> int TS2
<int>::x
; // expected-warning{{unused variable 'x'}}
103 template <typename T
, typename U
> int vt
= 0; // expected-warning {{unused variable template 'vt'}}
104 template <typename T
> int vt
<T
, void> = 0;
105 template <> int vt
<void, void> = 0; // expected-warning {{unused variable 'vt<void, void>'}}
109 // Ensure that friends of class templates are considered to have a dependent
110 // context and not marked unused.
112 template <typename T
> struct X
{
113 friend bool operator==(const X
&, const X
&) { return false; }
116 template <typename T
> void template_test(X
<T
> x
) {
126 namespace { struct A
{}; }
128 void test(A a
); // expected-warning {{unused function 'test'}}
129 extern "C" void test4(A a
);
132 namespace rdar8733476
{
133 static void foo() {} // expected-warning {{function 'foo' is not needed and will not be emitted}}
134 template <typename T
> static void foo_t() {} // expected-warning {{unused function template 'foo_t'}}
135 template <> void foo_t
<int>() {} // expected-warning {{function 'foo_t<int>' is not needed and will not be emitted}}
151 // FIXME: We should produce warnings for both of these.
152 static const int m
= n
;
154 static const double d
= 0.0; // expected-warning{{variable 'd' is not needed and will not be emitted}}
158 // FIXME: Should be "unused variable template 'var_t'" instead.
159 template <typename T
> const double var_t
= 0; // expected-warning {{unused variable 'var_t'}}
160 template <> const double var_t
<int> = 0; // expected-warning {{variable 'var_t<int>' is not needed and will not be emitted}}
161 int z
= sizeof(var_t
<int>); // expected-warning {{unused variable 'z'}}
165 namespace unused_nested
{
177 void func() { // expected-warning {{unused member function 'func'}}
179 } x
; // expected-warning {{unused variable 'x'}}
183 typedef struct { // expected-warning {{add a tag name}}
184 void bar(); // expected-note {{}}
185 } A
; // expected-note {{}}
188 void bar(); // expected-warning {{unused member function 'bar'}}
200 X a
= X(); // expected-warning {{unused variable 'a'}}
201 auto b
= X(); // expected-warning {{unused variable 'b'}}
204 namespace UndefinedInternalStaticMember
{
207 static const unsigned x
= 3;
215 void bar() { void func() __attribute__((used
)); }
216 static void func() {}
220 template <typename T
>
221 static void completeRedeclChainForTemplateSpecialization() {} // expected-warning {{unused function template 'completeRedeclChainForTemplateSpecialization'}}
225 #if __cplusplus >= 201103L
226 // FIXME: Warn on template definitions with no instantiations?
228 constexpr T pi
= T(3.14);
233 #if __cplusplus >= 201103L
234 // FIXME: We should warn on both of these.
235 static constexpr int constexpr3() { return 1; } // expected-warning {{unused function 'constexpr3'}}
236 constexpr int constexpr4() { return 2; }