1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace Enum
{
namespace
{
struct S
{
enum E
{
E1,
E2
};
E e;
};
}
void f(S s) { (void)s.e; }
}
namespace ElaboratedEnum
{
namespace
{
struct S
{
S()<--- Member variable 'S::e2' is not initialized in the constructor.
{
enum E1 e1 = E11;
(void)e1;
}
enum E1
{
E11,
E12
};
enum E2
{
E21,
E22
};
enum E2 e2;
};
}
void f()
{
S s;
(void)s;
(void)s.e2;
}
}
namespace UnusedEnum
{
namespace
{
struct S
{
enum E // expected-error {{unused class member [loplugin:unusedmember]}}
{
E1,
E2
};
};
}
void f() { (void)S::E1; }
}
namespace UnusedDataMember
{
namespace
{
struct NT
{
NT(int = 0) {}
~NT() {}
};
struct __attribute__((warn_unused)) T
{
T(int = 0) {}
~T() {}
};
struct S
{
int i1;
int i2; // expected-error {{unused class member [loplugin:unusedmember]}}
int const& i3; // expected-error {{unused class member [loplugin:unusedmember]}}
NT nt;
T t1;
T t2; // expected-error {{unused class member [loplugin:unusedmember]}}
T const& t3; // expected-error {{unused class member [loplugin:unusedmember]}}
S()<--- Member variable 'S::i2' is not initialized in the constructor.
: i1(0)
, i3(i1)
, t1(0)
, t3(t1)
{
(void)i1;
(void)t1;
}
};
}
void f()
{
S s;
(void)s;
}
}
namespace Alignof
{
namespace
{
struct S
{
int i;
};
}
void f() { (void)alignof(S const(&)[][10]); }
}
namespace Aligned
{
namespace
{
struct S1
{
int i;
};
struct S2
{
int i __attribute__((aligned(__alignof__(S1))));
};
}
void f()
{
S2 s;
s.i = 0;<--- Variable 's.i' is assigned a value that is never used.
}
}
namespace Bases
{
namespace
{
struct S1
{
int i1;
};
struct S2 : S1
{
int i2;
};
struct S3 : S2
{
};
}
void f() { (void)sizeof(S3); }
}
namespace Unnamed
{
namespace
{
struct S
{
struct
{
struct
{
int i;
} s2;
struct // anonymous struct extension (widely supported)
{
int j;<--- struct member 'Anonymous0::j' is never used.
};
int k;<--- struct member 'Anonymous0::k' is never used.
} s1;
#if false //TODO: see corresponding TODO in compilerplugins/clang/unusedmember.cxx
static constexpr struct
{
int l; // expected-error {{unused class member [loplugin:unusedmember]}}<--- struct member 'Anonymous2::l' is never used.
} s = {};
#endif
typedef struct
{
int m; // expected-error {{unused class member [loplugin:unusedmember]}}<--- struct member 't::m' is never used.
} t; // expected-error {{unused class member [loplugin:unusedmember]}}
};
}
void f()
{
(void)sizeof(S);
#if false //TODO: see corresponding TODO in compilerplugins/clang/unusedmember.cxx
(void)S::s; // avoid "unused variable 's'" (non-loplugin) warning
#endif
}
}
int main()
{
(void)&Enum::f;
(void)&ElaboratedEnum::f;
(void)&UnusedEnum::f;
(void)&UnusedDataMember::f;
(void)&Alignof::f;
(void)&Aligned::f;
(void)&Bases::f;
(void)&Unnamed::f;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|