1 // 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 3 4 #ifdef HEADER 5 headerstatic()6static void headerstatic() {} // expected-warning{{unused}} headerstaticinline()7static inline void headerstaticinline() {} 8 9 namespace { headeranon()10 void headeranon() {} // expected-warning{{unused}} headerinlineanon()11 inline void headerinlineanon() {} 12 } 13 14 namespace test7 15 { 16 template<typename T> foo(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<> foo(int)22 inline void foo(int) { } 23 24 // Partial specialization 25 template<typename T, typename U> bar(T,U)26 static inline void bar(T, U) { } 27 28 template<typename U> bar(int,U)29 inline void bar(int, U) { } 30 31 template<> bar(int,int)32 inline void bar(int, int) { } 33 }; 34 35 namespace pr19713 { 36 #if __cplusplus >= 201103L constexpr1()37 static constexpr int constexpr1() { return 1; } constexpr2()38 constexpr int constexpr2() { return 2; } 39 #endif 40 } 41 42 #else 43 #define HEADER 44 #include "warn-unused-filescoped.cpp" 45 46 static void f1(); // expected-warning{{unused}} 47 48 namespace { 49 void f2(); // expected-warning{{unused}} 50 f3()51 void f3() { } // expected-warning{{unused}} 52 53 struct S { m1__anon3bd8c9110211::S54 void m1() { } // expected-warning{{unused}} 55 void m2(); // expected-warning{{unused}} 56 void m3(); 57 S(const S&); 58 void operator=(const S&); 59 }; 60 61 template <typename T> 62 struct TS { 63 void m(); 64 }; m()65 template <> void TS<int>::m() { } // expected-warning{{unused}} 66 67 template <typename T> tf()68 void tf() { } tf()69 template <> void tf<int>() { } // expected-warning{{unused}} 70 71 struct VS { vm__anon3bd8c9110211::VS72 virtual void vm() { } 73 }; 74 75 struct SVS : public VS { vm__anon3bd8c9110211::SVS76 void vm() { } 77 }; 78 } 79 m3()80void S::m3() { } // expected-warning{{unused}} 81 f4()82static inline void f4() { } // expected-warning{{unused}} 83 const unsigned int cx = 0; // expected-warning{{unused}} 84 const unsigned int cy = 0; f5()85int f5() { return cy; } 86 87 static int x1; // expected-warning{{unused}} 88 89 namespace { 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 } 102 103 namespace 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 { operator ==(const X &,const X &)108 friend bool operator==(const X&, const X&) { return false; } 109 }; 110 } template_test(X<T> x)111 template <typename T> void template_test(X<T> x) { 112 (void)(x == x); 113 } test()114 void test() { 115 X<int> x; 116 template_test(x); 117 } 118 } 119 120 namespace test4 { 121 namespace { struct A {}; } 122 123 void test(A a); // expected-warning {{unused function}} 124 extern "C" void test4(A a); 125 } 126 127 namespace rdar8733476 { foo()128 static void foo() { } // expected-warning {{not needed and will not be emitted}} 129 130 template <int> bar()131 void bar() { 132 foo(); 133 } 134 } 135 136 namespace test5 { 137 static int n = 0; 138 static int &r = n; 139 int f(int &); 140 int k = f(r); 141 142 // FIXME: We should produce warnings for both of these. 143 static const int m = n; 144 int x = sizeof(m); 145 static const double d = 0.0; // expected-warning{{not needed and will not be emitted}} 146 int y = sizeof(d); 147 } 148 149 namespace unused_nested { 150 class outer { 151 void func1(); 152 struct { func2unused_nested::outer::__anon3bd8c9110608153 void func2() { 154 } 155 } x; 156 }; 157 } 158 159 namespace unused { 160 struct { funcunused::__anon3bd8c9110708161 void func() { // expected-warning {{unused member function}} 162 } 163 } x; // expected-warning {{unused variable}} 164 } 165 166 namespace 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 } 179 180 namespace 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 } 187 188 namespace UndefinedInternalStaticMember { 189 namespace { 190 struct X { 191 static const unsigned x = 3; 192 int y[x]; 193 }; 194 } 195 } 196 197 namespace test8 { 198 static void func(); bar()199void bar() { void func() __attribute__((used)); } func()200static void func() {} 201 } 202 203 namespace pr19713 { 204 #if __cplusplus >= 201103L 205 // FIXME: We should warn on both of these. constexpr3()206 static constexpr int constexpr3() { return 1; } // expected-warning {{unused}} constexpr4()207 constexpr int constexpr4() { return 2; } 208 #endif 209 } 210 211 #endif 212