Richard Smith | 623ef4b | 2012-10-28 04:47:21 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -std=c++98 %s |
| 2 | // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -std=c++11 %s |
Argyrios Kyrtzidis | bbc6454 | 2010-08-15 01:15:20 +0000 | [diff] [blame] | 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(); |
Argyrios Kyrtzidis | 06999f8 | 2010-08-15 10:17:33 +0000 | [diff] [blame] | 15 | S(const S&); |
| 16 | void operator=(const S&); |
Argyrios Kyrtzidis | bbc6454 | 2010-08-15 01:15:20 +0000 | [diff] [blame] | 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 | } |
Chandler Carruth | ef9d09c | 2011-01-03 19:27:19 +0000 | [diff] [blame] | 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 | } |
John McCall | af8ca37 | 2011-02-10 06:50:24 +0000 | [diff] [blame] | 70 | void test() { |
| 71 | X<int> x; |
Chandler Carruth | ef9d09c | 2011-01-03 19:27:19 +0000 | [diff] [blame] | 72 | template_test(x); |
| 73 | } |
| 74 | } |
John McCall | af8ca37 | 2011-02-10 06:50:24 +0000 | [diff] [blame] | 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 | } |
Argyrios Kyrtzidis | 6b6b42a | 2011-04-19 19:51:10 +0000 | [diff] [blame] | 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 | } |
Richard Smith | 623ef4b | 2012-10-28 04:47:21 +0000 | [diff] [blame] | 91 | |
| 92 | namespace test5 { |
| 93 | static int n = 0; |
| 94 | static int &r = n; |
| 95 | int f(int &); |
| 96 | int k = f(r); |
| 97 | |
Richard Smith | c36e359 | 2012-10-28 07:39:29 +0000 | [diff] [blame] | 98 | // FIXME: We should produce warnings for both of these. |
| 99 | static const int m = n; |
Richard Smith | 623ef4b | 2012-10-28 04:47:21 +0000 | [diff] [blame] | 100 | int x = sizeof(m); |
Richard Smith | c36e359 | 2012-10-28 07:39:29 +0000 | [diff] [blame] | 101 | static const double d = 0.0; |
Richard Smith | 623ef4b | 2012-10-28 04:47:21 +0000 | [diff] [blame] | 102 | int y = sizeof(d); |
| 103 | } |
David Blaikie | 66cff72 | 2012-11-14 01:52:05 +0000 | [diff] [blame^] | 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 | } |