nss: upgrade to release 3.73
[LibreOffice.git] / compilerplugins / clang / test / unusedmember.cxx
blob00b136249acaae0d230342885f2500e4d8329dcc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 namespace Enum
12 namespace
14 struct S
16 enum E
18 E1,
21 E e;
24 void f(S s) { (void)s.e; }
27 namespace ElaboratedEnum
29 namespace
31 struct S
33 S()
35 enum E1 e1 = E11;
36 (void)e1;
38 enum E1
40 E11,
41 E12
43 enum E2
45 E21,
46 E22
48 enum E2 e2;
51 void f()
53 S s;
54 (void)s;
55 (void)s.e2;
59 namespace UnusedEnum
61 namespace
63 struct S
65 enum E // expected-error {{unused class member [loplugin:unusedmember]}}
67 E1,
72 void f() { (void)S::E1; }
75 namespace UnusedDataMember
77 namespace
79 struct NT
81 NT(int = 0) {}
82 ~NT() {}
84 struct __attribute__((warn_unused)) T
86 T(int = 0) {}
87 ~T() {}
89 struct S
91 int i1;
92 int i2; // expected-error {{unused class member [loplugin:unusedmember]}}
93 int const& i3; // expected-error {{unused class member [loplugin:unusedmember]}}
94 NT nt;
95 T t1;
96 T t2; // expected-error {{unused class member [loplugin:unusedmember]}}
97 T const& t3; // expected-error {{unused class member [loplugin:unusedmember]}}
98 S()
99 : i1(0)
100 , i3(i1)
101 , t1(0)
102 , t3(t1)
104 (void)i1;
105 (void)t1;
109 void f()
111 S s;
112 (void)s;
116 namespace Alignof
118 namespace
120 struct S
122 int i;
125 void f() { (void)alignof(S const(&)[][10]); }
128 namespace Aligned
130 namespace
132 struct S1
134 int i;
136 struct S2
138 int i __attribute__((aligned(__alignof__(S1))));
141 void f()
143 S2 s;
144 s.i = 0;
148 namespace Bases
150 namespace
152 struct S1
154 int i1;
156 struct S2 : S1
158 int i2;
160 struct S3 : S2
164 void f() { (void)sizeof(S3); }
167 namespace Unnamed
169 namespace
171 struct S
173 struct
175 struct
177 int i;
178 } s2;
179 struct // anonymous struct extension (widely supported)
181 int j;
183 int k;
184 } s1;
185 #if false //TODO: see corresponding TODO in compilerplugins/clang/unusedmember.cxx
186 static constexpr struct
188 int l; // expected-error {{unused class member [loplugin:unusedmember]}}
189 } s = {};
190 #endif
191 typedef struct
193 int m; // expected-error {{unused class member [loplugin:unusedmember]}}
194 } t; // expected-error {{unused class member [loplugin:unusedmember]}}
197 void f()
199 (void)sizeof(S);
200 #if false //TODO: see corresponding TODO in compilerplugins/clang/unusedmember.cxx
201 (void)S::s; // avoid "unused variable 's'" (non-loplugin) warning
202 #endif
206 int main()
208 (void)&Enum::f;
209 (void)&ElaboratedEnum::f;
210 (void)&UnusedEnum::f;
211 (void)&UnusedDataMember::f;
212 (void)&Alignof::f;
213 (void)&Aligned::f;
214 (void)&Bases::f;
215 (void)&Unnamed::f;
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */