Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 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 |
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 | |
Richard Smith | a90ee35 | 2014-05-11 21:25:24 +0000 | [diff] [blame] | 35 | namespace pr19713 { |
| 36 | #if __cplusplus >= 201103L |
| 37 | static constexpr int constexpr1() { return 1; } |
| 38 | constexpr int constexpr2() { return 2; } |
| 39 | #endif |
| 40 | } |
| 41 | |
Eli Friedman | 5ef2175 | 2013-09-10 03:05:56 +0000 | [diff] [blame] | 42 | #else |
| 43 | #define HEADER |
| 44 | #include "warn-unused-filescoped.cpp" |
| 45 | |
Argyrios Kyrtzidis | 1b30d9c | 2010-08-15 01:15:20 +0000 | [diff] [blame] | 46 | static void f1(); // expected-warning{{unused}} |
| 47 | |
| 48 | namespace { |
| 49 | void f2(); // expected-warning{{unused}} |
| 50 | |
| 51 | void f3() { } // expected-warning{{unused}} |
| 52 | |
| 53 | struct S { |
| 54 | void m1() { } // expected-warning{{unused}} |
| 55 | void m2(); // expected-warning{{unused}} |
| 56 | void m3(); |
Argyrios Kyrtzidis | 04c7fa0 | 2010-08-15 10:17:33 +0000 | [diff] [blame] | 57 | S(const S&); |
| 58 | void operator=(const S&); |
Argyrios Kyrtzidis | 1b30d9c | 2010-08-15 01:15:20 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | template <typename T> |
| 62 | struct TS { |
| 63 | void m(); |
| 64 | }; |
| 65 | template <> void TS<int>::m() { } // expected-warning{{unused}} |
| 66 | |
| 67 | template <typename T> |
| 68 | void tf() { } |
| 69 | template <> void tf<int>() { } // expected-warning{{unused}} |
| 70 | |
| 71 | struct VS { |
| 72 | virtual void vm() { } |
| 73 | }; |
| 74 | |
| 75 | struct SVS : public VS { |
| 76 | void vm() { } |
| 77 | }; |
| 78 | } |
| 79 | |
| 80 | void S::m3() { } // expected-warning{{unused}} |
| 81 | |
Eli Friedman | 5ef2175 | 2013-09-10 03:05:56 +0000 | [diff] [blame] | 82 | static inline void f4() { } // expected-warning{{unused}} |
| 83 | const unsigned int cx = 0; // expected-warning{{unused}} |
| 84 | const unsigned int cy = 0; |
| 85 | int f5() { return cy; } |
Argyrios Kyrtzidis | 1b30d9c | 2010-08-15 01:15:20 +0000 | [diff] [blame] | 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 | } |
Chandler Carruth | 8e66651 | 2011-01-03 19:27:19 +0000 | [diff] [blame] | 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 { |
| 108 | friend bool operator==(const X&, const X&) { return false; } |
| 109 | }; |
| 110 | } |
| 111 | template <typename T> void template_test(X<T> x) { |
| 112 | (void)(x == x); |
| 113 | } |
John McCall | f768aa7 | 2011-02-10 06:50:24 +0000 | [diff] [blame] | 114 | void test() { |
| 115 | X<int> x; |
Chandler Carruth | 8e66651 | 2011-01-03 19:27:19 +0000 | [diff] [blame] | 116 | template_test(x); |
| 117 | } |
| 118 | } |
John McCall | f768aa7 | 2011-02-10 06:50:24 +0000 | [diff] [blame] | 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 | } |
Argyrios Kyrtzidis | 1618023 | 2011-04-19 19:51:10 +0000 | [diff] [blame] | 126 | |
| 127 | namespace rdar8733476 { |
| 128 | static void foo() { } // expected-warning {{not needed and will not be emitted}} |
| 129 | |
| 130 | template <int> |
| 131 | void bar() { |
| 132 | foo(); |
| 133 | } |
| 134 | } |
Richard Smith | 27501e7 | 2012-10-28 04:47:21 +0000 | [diff] [blame] | 135 | |
| 136 | namespace test5 { |
| 137 | static int n = 0; |
| 138 | static int &r = n; |
| 139 | int f(int &); |
| 140 | int k = f(r); |
| 141 | |
Richard Smith | 59a8e49 | 2012-10-28 07:39:29 +0000 | [diff] [blame] | 142 | // FIXME: We should produce warnings for both of these. |
| 143 | static const int m = n; |
Richard Smith | 27501e7 | 2012-10-28 04:47:21 +0000 | [diff] [blame] | 144 | int x = sizeof(m); |
Eli Friedman | 5ef2175 | 2013-09-10 03:05:56 +0000 | [diff] [blame] | 145 | 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] | 146 | int y = sizeof(d); |
| 147 | } |
David Blaikie | 095deba | 2012-11-14 01:52:05 +0000 | [diff] [blame] | 148 | |
| 149 | namespace unused_nested { |
| 150 | class outer { |
| 151 | void func1(); |
| 152 | struct { |
| 153 | void func2() { |
| 154 | } |
| 155 | } x; |
| 156 | }; |
| 157 | } |
| 158 | |
| 159 | namespace unused { |
| 160 | struct { |
| 161 | void func() { // expected-warning {{unused member function}} |
| 162 | } |
| 163 | } x; // expected-warning {{unused variable}} |
| 164 | } |
Rafael Espindola | ea7537f | 2012-12-30 21:42:26 +0000 | [diff] [blame] | 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 | } |
Rafael Espindola | d2ecc13 | 2013-01-03 04:29:20 +0000 | [diff] [blame] | 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 | } |
Eli Friedman | 5ef2175 | 2013-09-10 03:05:56 +0000 | [diff] [blame] | 187 | |
Eli Friedman | a5dfebd | 2013-09-10 21:10:25 +0000 | [diff] [blame] | 188 | namespace UndefinedInternalStaticMember { |
| 189 | namespace { |
| 190 | struct X { |
| 191 | static const unsigned x = 3; |
| 192 | int y[x]; |
| 193 | }; |
| 194 | } |
| 195 | } |
| 196 | |
Rafael Espindola | b093885 | 2013-10-25 01:28:12 +0000 | [diff] [blame] | 197 | namespace test8 { |
| 198 | static void func(); |
| 199 | void bar() { void func() __attribute__((used)); } |
| 200 | static void func() {} |
| 201 | } |
| 202 | |
Richard Smith | a90ee35 | 2014-05-11 21:25:24 +0000 | [diff] [blame] | 203 | namespace pr19713 { |
| 204 | #if __cplusplus >= 201103L |
| 205 | // FIXME: We should warn on both of these. |
| 206 | static constexpr int constexpr3() { return 1; } // expected-warning {{unused}} |
| 207 | constexpr int constexpr4() { return 2; } |
| 208 | #endif |
| 209 | } |
| 210 | |
Eli Friedman | 5ef2175 | 2013-09-10 03:05:56 +0000 | [diff] [blame] | 211 | #endif |