warn-unused-filescoped.cpp revision 66cff7257698d5528632917d38f9a3037bb1506d
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
3
4static void f1(); // expected-warning{{unused}}
5
6namespace {
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
38void S::m3() { }  // expected-warning{{unused}}
39
40static inline void f4() { }
41const unsigned int cx = 0;
42
43static int x1;  // expected-warning{{unused}}
44
45namespace {
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
59namespace 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
76namespace test4 {
77  namespace { struct A {}; }
78
79  void test(A a); // expected-warning {{unused function}}
80  extern "C" void test4(A a);
81}
82
83namespace 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
92namespace 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
105namespace unused_nested {
106  class outer {
107    void func1();
108    struct {
109      void func2() {
110      }
111    } x;
112  };
113}
114
115namespace unused {
116  struct {
117    void func() { // expected-warning {{unused member function}}
118    }
119  } x; // expected-warning {{unused variable}}
120}
121