BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsla_unused.h
Go to the documentation of this file.
1
/// @file bsla_unused.h
2
///
3
/// The content of this file has been pre-processed for Doxygen.
4
///
5
6
7
// bsla_unused.h -*-C++-*-
8
#ifndef INCLUDED_BSLA_UNUSED
9
#define INCLUDED_BSLA_UNUSED
10
11
#include <
bsls_ident.h
>
12
BSLS_IDENT
(
"$Id: $"
)
13
14
/// @defgroup bsla_unused bsla_unused
15
/// @brief Provide a macro to suppress "unused" warnings.
16
/// @addtogroup bsl
17
/// @{
18
/// @addtogroup bsla
19
/// @{
20
/// @addtogroup bsla_unused
21
/// @{
22
///
23
/// <h1> Outline </h1>
24
/// * <a href="#bsla_unused-purpose"> Purpose</a>
25
/// * <a href="#bsla_unused-macros"> Macros </a>
26
/// * <a href="#bsla_unused-description"> Description </a>
27
/// * <a href="#bsla_unused-macro-reference"> Macro Reference </a>
28
/// * <a href="#bsla_unused-usage"> Usage </a>
29
/// * <a href="#bsla_unused-example-1-unused-warnings"> Example 1: "Unused" Warnings </a>
30
///
31
/// # Purpose {#bsla_unused-purpose}
32
/// Provide a macro to suppress "unused" warnings.
33
///
34
/// @deprecated Use @ref bsla_maybeunused instead.
35
///
36
/// # Macros {#bsla_unused-macros}
37
///
38
/// - BSLA_UNUSED: do not warn if annotated entity is unused
39
/// - BSLA_UNUSED_IS_ACTIVE: defined if `BSLA_UNUSED` is active
40
///
41
/// @see bsla_annotations, bsla_maybeunused
42
///
43
/// # Description {#bsla_unused-description}
44
/// This component provides a preprocessor macro that will suppress
45
/// "unused" warnings on a locally defined function, type, or variable that is
46
/// not used.
47
///
48
/// Note that the similar macro, `BSLA_MAYBE_UNUSED`, aliasing the standard
49
/// `[[maybe_unused]]` attribute, may be considered for use instead of this
50
/// macro.
51
///
52
/// ## Macro Reference {#bsla_unused-macro-reference}
53
///
54
///
55
/// `BSLA_UNUSED`:
56
/// This annotation indicates that the so-annotated function, variable, or
57
/// type is possibly unused and the compiler should not generate a warning
58
/// for the unused identifier.
59
///
60
/// `BSLA_UNUSED_IS_ACTIVE`:
61
/// The macro `BSLA_UNUSED_IS_ACTIVE` is defined if `BSLA_UNUSED` expands
62
/// to something with the desired effect; otherwise `BSLA_UNUSED_IS_ACTIVE`
63
/// is not defined and `BSLA_UNUSED` expands to nothing.
64
///
65
/// ## Usage {#bsla_unused-usage}
66
///
67
///
68
/// This section illustrates intended use of this component.
69
///
70
/// ### Example 1: "Unused" Warnings {#bsla_unused-example-1-unused-warnings}
71
///
72
///
73
/// First, we define a namespace, `warn`, within the unnamed namespace with a
74
/// type, a function, and a variable in it. They are unused:
75
/// @code
76
/// namespace {
77
/// namespace warn {
78
///
79
/// double x;
80
///
81
/// struct ResultRec {
82
/// double d_x;
83
/// double d_y;
84
/// };
85
///
86
/// /// Solve the quadratic function for the specified 'a', 'b', and 'c',
87
/// /// where '0 = a * x^2 + b * x + c'. If the quadratic has no solutions,
88
/// /// return a non-zero value, and set the specified 'zeroA' and 'zeroB'
89
/// /// to those solutions and return 0 otherwise. The specified
90
/// /// 'cubeFactor' and 'zeroC' are unused for now but will be used in
91
/// /// future expansion of the function to handle cubic polynomials.
92
/// int quadratic(double *zeroA,
93
/// double *zeroB,
94
/// double *zeroC,
95
/// double cubeFactor,
96
/// double a,
97
/// double b,
98
/// double c)
99
/// {
100
/// const double discriminant = b * b - 4 * a * c;
101
/// if (discriminant < 0 || 0.0 == a) {
102
/// *zeroA = *zeroB = 0.0;
103
/// return -1; // RETURN
104
/// }
105
///
106
/// const double root = ::sqrt(discriminant);
107
/// *zeroA = (-b + root) / (2 * a);
108
/// *zeroB = (-b - root) / (2 * a);
109
///
110
/// return 0;
111
/// }
112
///
113
/// } // close namespace warn
114
/// } // close unnamed namespace
115
/// @endcode
116
/// Then, we observe the warnings:
117
/// @code
118
/// .../bsla_unused.t.cpp:135:27: warning: unused parameter 'zeroC'
119
/// [-Wunused-parameter]
120
/// double *zeroC,
121
/// ~~~~~~~~^~~~~
122
/// .../bsla_unused.t.cpp:136:26: warning: unused parameter 'cubeFactor'
123
/// [-Wunused-parameter]
124
/// double cubeFactor,
125
/// ~~~~~~~^~~~~~~~~~
126
/// .../bsla_unused.t.cpp:133:9: warning: 'int {anonymous}::warn::
127
/// quadratic(double*, double*, double*, double, double, double, double)'
128
/// defined but not used [-Wunused-function]
129
/// int quadratic(double *zeroA,
130
/// ^~~~~~~~~
131
/// .../bsla_unused.t.cpp:126:12: warning: '{anonymous}::warn::x' defined but
132
/// not used [-Wunused-variable]
133
/// double x;
134
/// ^
135
/// @endcode
136
/// Note that none of the compilers currently in use by the development team
137
/// issue a warning on the unused `warn::ResultRec`, but some in the future
138
/// might. In the meantime, `BSLA_UNUSED` is tolerated on type declarations
139
/// without resulting in a syntax error.
140
///
141
/// Next, we define a namespace, `nowarn`, within the unused namespace with
142
/// exactly the same unused entities, using the `BSLA_UNUSED` annotation to
143
/// silence the warnings:
144
/// @code
145
/// namespace {
146
/// namespace nowarn {
147
///
148
/// struct ResultRec {
149
/// double d_x;
150
/// double d_y;
151
/// } BSLA_UNUSED;
152
///
153
/// double x BSLA_UNUSED;
154
///
155
/// /// Solve the quadratic function for the specified 'a', 'b', and 'c',
156
/// /// where '0 = a * x^2 + b * x + c'. If the quadratic has no solutions,
157
/// /// return a non-zero value, and set the specified 'zeroA' and 'zeroB'
158
/// /// to those solutions and return 0 otherwise. The specified
159
/// /// 'cubeFactor' and 'zeroC' are unused for now but will be used in
160
/// /// future expansion of the function to handle cubic polynomials.
161
/// int quadratic(double *zeroA,
162
/// double *zeroB,
163
/// BSLA_UNUSED double *zeroC,
164
/// BSLA_UNUSED double cubeFactor,
165
/// double a,
166
/// double b,
167
/// double c) BSLA_UNUSED;
168
///
169
/// int quadratic(double *zeroA,
170
/// double *zeroB,
171
/// BSLA_UNUSED double *zeroC,
172
/// BSLA_UNUSED double cubeFactor,
173
/// double a,
174
/// double b,
175
/// double c)
176
/// {
177
/// const double discriminant = b * b - 4 * a * c;
178
/// if (discriminant < 0 || 0.0 == a) {
179
/// *zeroA = *zeroB = 0.0;
180
/// return -1; // RETURN
181
/// }
182
///
183
/// const double root = ::sqrt(discriminant);
184
/// *zeroA = (-b + root) / (2 * a);
185
/// *zeroB = (-b - root) / (2 * a);
186
///
187
/// return 0;
188
/// }
189
///
190
/// } // close namespace nowarn
191
/// } // close unnamed namespace
192
/// @endcode
193
/// Finally, we observe that the warnings for the `nowarn` namespace are
194
/// suppressed.
195
/// @}
196
/** @} */
197
/** @} */
198
199
/** @addtogroup bsl
200
* @{
201
*/
202
/** @addtogroup bsla
203
* @{
204
*/
205
/** @addtogroup bsla_unused
206
* @{
207
*/
208
209
#include <bsls_platform.h>
210
211
// Note that it is highly recommended to use 'BSLA_MAYBE_UNUSED'
212
// ('[[maybe_unused]]') where available, as it is supported by a large number
213
// of platforms, but that has more specific constraints over where it can be
214
// syntactically placed than the older vendor annotations.
215
216
// =============================
217
// Checks for Pre-Defined macros
218
// =============================
219
220
#if defined(BSLA_UNUSED)
221
#error BSLA_UNUSED is already defined!
222
#endif
223
224
#if defined(BSLA_UNUSED_IS_ACTIVE)
225
#error BSLA_UNUSED_IS_ACTIVE is already defined!
226
#endif
227
228
// =========================
229
// Set macros as appropriate
230
// =========================
231
232
#if defined(BSLS_PLATFORM_CMP_GNU) || defined(BSLS_PLATFORM_CMP_CLANG)
233
#define BSLA_UNUSED __attribute__((__unused__))
234
235
#define BSLA_UNUSED_IS_ACTIVE 1
236
#else
237
#define BSLA_UNUSED
238
#endif
239
240
#endif
241
242
// ----------------------------------------------------------------------------
243
// Copyright 2019 Bloomberg Finance L.P.
244
//
245
// Licensed under the Apache License, Version 2.0 (the "License");
246
// you may not use this file except in compliance with the License.
247
// You may obtain a copy of the License at
248
//
249
// http://www.apache.org/licenses/LICENSE-2.0
250
//
251
// Unless required by applicable law or agreed to in writing, software
252
// distributed under the License is distributed on an "AS IS" BASIS,
253
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
254
// See the License for the specific language governing permissions and
255
// limitations under the License.
256
// ----------------------------- END-OF-FILE ----------------------------------
257
258
/** @} */
259
/** @} */
260
/** @} */
bsls_ident.h
BSLS_IDENT
#define BSLS_IDENT(str)
Definition
bsls_ident.h:195
doxygen_input
bde
groups
bsl
bsla
bsla_unused.h
Generated by
1.9.8