1 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-c++11-extensions -std=c++98 %s 2 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -std=c++11 %s 3 4 #ifdef HEADER 5 6 static void headerstatic() {} // expected-warning{{unused}} 7 static inline void headerstaticinline() {} 8 9 namespace { 10 void headeranon() {} // expected-warning{{unused}} 11 inline void headerinlineanon() {} 12 } 13 14 namespace 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 39 static void f1(); // expected-warning{{unused}} 40 41 namespace { 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(); 50 S(const S&); 51 void operator=(const S&); 52 }; 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 73 void S::m3() { } // expected-warning{{unused}} 74 75 static inline void f4() { } // expected-warning{{unused}} 76 const unsigned int cx = 0; // expected-warning{{unused}} 77 const unsigned int cy = 0; 78 int f5() { return cy; } 79 80 static int x1; // expected-warning{{unused}} 81 82 namespace { 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 } 95 96 namespace 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 } 107 void test() { 108 X<int> x; 109 template_test(x); 110 } 111 } 112 113 namespace test4 { 114 namespace { struct A {}; } 115 116 void test(A a); // expected-warning {{unused function}} 117 extern "C" void test4(A a); 118 } 119 120 namespace 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 } 128 129 namespace test5 { 130 static int n = 0; 131 static int &r = n; 132 int f(int &); 133 int k = f(r); 134 135 // FIXME: We should produce warnings for both of these. 136 static const int m = n; 137 int x = sizeof(m); 138 static const double d = 0.0; // expected-warning{{not needed and will not be emitted}} 139 int y = sizeof(d); 140 } 141 142 namespace unused_nested { 143 class outer { 144 void func1(); 145 struct { 146 void func2() { 147 } 148 } x; 149 }; 150 } 151 152 namespace unused { 153 struct { 154 void func() { // expected-warning {{unused member function}} 155 } 156 } x; // expected-warning {{unused variable}} 157 } 158 159 namespace 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 } 172 173 namespace 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 } 180 181 namespace UndefinedInternalStaticMember { 182 namespace { 183 struct X { 184 static const unsigned x = 3; 185 int y[x]; 186 }; 187 } 188 } 189 190 namespace test8 { 191 static void func(); 192 void bar() { void func() __attribute__((used)); } 193 static void func() {} 194 } 195 196 #endif 197