Rafael Espindola | d2ecc13 | 2013-01-03 04:29:20 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-c++11-extensions -std=c++98 %s |
Richard Smith | 27501e7 | 2012-10-28 04:47:21 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -std=c++11 %s |
Argyrios Kyrtzidis | 1b30d9c | 2010-08-15 01:15:20 +0000 | [diff] [blame] | 3 | |
Eli Friedman | 5ef2175 | 2013-09-10 03:05:56 +0000 | [diff] [blame^] | 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 | |
Argyrios Kyrtzidis | 1b30d9c | 2010-08-15 01:15:20 +0000 | [diff] [blame] | 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(); |
Argyrios Kyrtzidis | 04c7fa0 | 2010-08-15 10:17:33 +0000 | [diff] [blame] | 50 | S(const S&); |
| 51 | void operator=(const S&); |
Argyrios Kyrtzidis | 1b30d9c | 2010-08-15 01:15:20 +0000 | [diff] [blame] | 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 | |
Eli Friedman | 5ef2175 | 2013-09-10 03:05:56 +0000 | [diff] [blame^] | 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; } |
Argyrios Kyrtzidis | 1b30d9c | 2010-08-15 01:15:20 +0000 | [diff] [blame] | 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 | } |
Chandler Carruth | 8e66651 | 2011-01-03 19:27:19 +0000 | [diff] [blame] | 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 | } |
John McCall | f768aa7 | 2011-02-10 06:50:24 +0000 | [diff] [blame] | 107 | void test() { |
| 108 | X<int> x; |
Chandler Carruth | 8e66651 | 2011-01-03 19:27:19 +0000 | [diff] [blame] | 109 | template_test(x); |
| 110 | } |
| 111 | } |
John McCall | f768aa7 | 2011-02-10 06:50:24 +0000 | [diff] [blame] | 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 | } |
Argyrios Kyrtzidis | 1618023 | 2011-04-19 19:51:10 +0000 | [diff] [blame] | 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 | } |
Richard Smith | 27501e7 | 2012-10-28 04:47:21 +0000 | [diff] [blame] | 128 | |
| 129 | namespace test5 { |
| 130 | static int n = 0; |
| 131 | static int &r = n; |
| 132 | int f(int &); |
| 133 | int k = f(r); |
| 134 | |
Richard Smith | 59a8e49 | 2012-10-28 07:39:29 +0000 | [diff] [blame] | 135 | // FIXME: We should produce warnings for both of these. |
| 136 | static const int m = n; |
Richard Smith | 27501e7 | 2012-10-28 04:47:21 +0000 | [diff] [blame] | 137 | int x = sizeof(m); |
Eli Friedman | 5ef2175 | 2013-09-10 03:05:56 +0000 | [diff] [blame^] | 138 | static const double d = 0.0; // expected-warning{{not needed and will not be emitted}} |
Richard Smith | 27501e7 | 2012-10-28 04:47:21 +0000 | [diff] [blame] | 139 | int y = sizeof(d); |
| 140 | } |
David Blaikie | 095deba | 2012-11-14 01:52:05 +0000 | [diff] [blame] | 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 | } |
Rafael Espindola | ea7537f | 2012-12-30 21:42:26 +0000 | [diff] [blame] | 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 | } |
Rafael Espindola | d2ecc13 | 2013-01-03 04:29:20 +0000 | [diff] [blame] | 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 | } |
Eli Friedman | 5ef2175 | 2013-09-10 03:05:56 +0000 | [diff] [blame^] | 180 | |
| 181 | #endif |