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 static void f1(); // expected-warning{{unused}} 5 6 namespace { 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(); 15 S(const S&); 16 void operator=(const S&); 17 }; 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 38 void S::m3() { } // expected-warning{{unused}} 39 40 static inline void f4() { } 41 const unsigned int cx = 0; 42 43 static int x1; // expected-warning{{unused}} 44 45 namespace { 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 } 58 59 namespace 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 } 70 void test() { 71 X<int> x; 72 template_test(x); 73 } 74 } 75 76 namespace test4 { 77 namespace { struct A {}; } 78 79 void test(A a); // expected-warning {{unused function}} 80 extern "C" void test4(A a); 81 } 82 83 namespace 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 } 91 92 namespace test5 { 93 static int n = 0; 94 static int &r = n; 95 int f(int &); 96 int k = f(r); 97 98 // FIXME: We should produce warnings for both of these. 99 static const int m = n; 100 int x = sizeof(m); 101 static const double d = 0.0; 102 int y = sizeof(d); 103 } 104 105 namespace unused_nested { 106 class outer { 107 void func1(); 108 struct { 109 void func2() { 110 } 111 } x; 112 }; 113 } 114 115 namespace unused { 116 struct { 117 void func() { // expected-warning {{unused member function}} 118 } 119 } x; // expected-warning {{unused variable}} 120 } 121 122 namespace 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 } 135 136 namespace 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 157 namespace 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 } 164