BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsla_annotations.h
Go to the documentation of this file.
1
/// @file bsla_annotations.h
2
///
3
/// The content of this file has been pre-processed for Doxygen.
4
///
5
6
7
// bsla_annotations.h -*-C++-*-
8
#ifndef INCLUDED_BSLA_ANNOTATIONS
9
#define INCLUDED_BSLA_ANNOTATIONS
10
11
#include <
bsls_ident.h
>
12
BSLS_IDENT
(
"$Id: $"
)
13
14
/// @defgroup bsla_annotations bsla_annotations
15
/// @brief Provide support for compiler annotations for compile-time safety.
16
/// @addtogroup bsl
17
/// @{
18
/// @addtogroup bsla
19
/// @{
20
/// @addtogroup bsla_annotations
21
/// @{
22
///
23
/// <h1> Outline </h1>
24
/// * <a href="#bsla_annotations-purpose"> Purpose</a>
25
/// * <a href="#bsla_annotations-macros"> Macros </a>
26
/// * <a href="#bsla_annotations-description"> Description </a>
27
/// * <a href="#bsla_annotations-macro-reference"> Macro Reference </a>
28
/// * <a href="#bsla_annotations-usage"> Usage </a>
29
///
30
/// # Purpose {#bsla_annotations-purpose}
31
/// Provide support for compiler annotations for compile-time safety.
32
///
33
/// # Macros {#bsla_annotations-macros}
34
///
35
/// - BSLA_DEPRECATED: warn if annotated (deprecated) entity is used
36
/// - BSLA_ERROR(QUOTED_MESSAGE): emit error message and fail compilation
37
/// - BSLA_FALLTHROUGH: do not warn if `switch` `case` falls through
38
/// - BSLA_FORMAT(FMT_IDX): validate `printf`-style format spec in `n`th argument
39
/// - BSLA_MAYBE_UNUSED: suppress compiler warnings on unused entities
40
/// - BSLA_NODISCARD: warn if annotated function result is not used
41
/// - BSLA_NONNULLARG(...): warn if indexed arguments are NULL
42
/// - BSLA_NONNULLARGS: warn if any arguments are NULL
43
/// - BSLA_NORETURN: issue a compiler warning if function returns normally
44
/// - BSLA_NULLTERMINATED: warn if last argument is non-NULL
45
/// - BSLA_NULLTERMINATEDAT(ARG_IDX): warn if argument at `ARG_IDX` is non-NULL
46
/// - BSLA_PRINTF(FMTIDX, STARTIDX): validate `printf` format and arguments
47
/// - BSLA_SCANF(FMTIDX, STARTIDX): validate `scanf` format and arguments
48
/// - BSLA_UNUSED: do not warn if annotated entity is unused
49
/// - BSLA_USED: emit annotated entity even if not referenced
50
/// - BSLA_WARNING(QUOTED_MESSAGE): emit warning message during compilation
51
/// - BSLA_DEPRECATED_IS_ACTIVE: defined if `BSLA_DEPRECATED` is active
52
/// - BSLA_ERROR_IS_ACTIVE: defined if `BSLA_ERROR` is active
53
/// - BSLA_FALLTHROUGH_IS_ACTIVE: defined if `BSLA_FALLTHROUGH` is active
54
/// - BSLA_FORMAT_IS_ACTIVE: defined if `BSLA_FORMAT` is active
55
/// - BSLA_MAYBE_UNUSED_IS_ACTIVE: defined if `BSLA_MAYBE_UNUSED` is active
56
/// - BSLA_NODISCARD_IS_ACTIVE: defined if `BSLA_NODISCARD` is active
57
/// - BSLA_NONNULLARG_IS_ACTIVE: defined if `BSLA_NONNULLARG` is active
58
/// - BSLA_NONNULLARGS_IS_ACTIVE: defined if `BSLA_NONNULLARGS` is active
59
/// - BSLA_NORETURN_IS_ACTIVE: defined if `BSLA_NORETURN` is active
60
/// - BSLA_NULLTERMINATED_IS_ACTIVE: defined if `BSLA_NULLTERMINATED` is active
61
/// - BSLA_NULLTERMINATEDAT_IS_ACTIVE: defined if `BSLA_NULLTERMINATEDAT` active
62
/// - BSLA_PRINTF_IS_ACTIVE: defined if `BSLA_PRINTF` is active
63
/// - BSLA_SCANF_IS_ACTIVE: defined if `BSLA_SCANF` is active
64
/// - BSLA_UNUSED_IS_ACTIVE: defined if `BSLA_UNUSED` is active
65
/// - BSLA_USED_IS_ACTIVE: defined if `BSLA_USED` is active
66
/// - BSLA_WARNING_IS_ACTIVE: defined if `BSLA_WARNING` is active
67
///
68
/// # Description {#bsla_annotations-description}
69
/// This component exists to provide a single component whose
70
/// header can be included to transitively include all of the annotation macros
71
/// defined in the `bsla` package. The macros that are transitively included by
72
/// this component correspond to various compiler features, and can be used to
73
/// annotate code for specific compile-time safety checks.
74
///
75
/// For the most part, these compile-time annotations are supported only when
76
/// the `BSLS_PLATFORM_CMP_GNU` or `BSLS_PLATFORM_CMP_CLANG` preprocessor macros
77
/// are defined. Other compilers may implement a few annotations, but the
78
/// macros should be expected to work only with compilers for which
79
/// `BSLS_PLATFORM_CMP_GNU` or `BSLS_PLATFORM_CMP_CLANG` is defined.
80
///
81
/// ## Macro Reference {#bsla_annotations-macro-reference}
82
///
83
///
84
/// `BSLA_DEPRECATED`:
85
/// This annotation will, when used, cause a compile-time warning if the
86
/// so-annotated function, variable, or type is used anywhere within the
87
/// source file. This is useful, for example, when identifying functions
88
/// that are expected to be removed in a future version of a library. The
89
/// warning includes the location of the declaration of the deprecated
90
/// entity to enable users to find further information about the
91
/// deprecation, or what they should use instead.
92
///
93
/// `BSLA_ERROR(QUOTED_MESSAGE)`:
94
/// This annotation, when used, will cause a compile-time error when a call
95
/// to the so-annotated function is not removed through dead-code
96
/// elimination or other optimizations. While it is possible to leave the
97
/// function undefined, thus incurring a link-time failure, with the use of
98
/// this macro the invalid call will be diagnosed earlier (i.e., at compile
99
/// time), and the diagnostic will include the location of the function
100
/// call. The message `QUOTED_MESSAGE`, which should be a double-quoted
101
/// string, will appear in the error message.
102
///
103
/// `BSLA_FALLTHROUGH`:
104
/// This annotation should be placed in a `case` clause as the last
105
/// statement within a flow of control that is expected to allow control to
106
/// fall through instead of ending with a `break`, `continue`, or `return`.
107
/// This will prevent compilers from warning about fall-through. The
108
/// `BSLA_FALLTHROUGH` must be followed by a semicolon and may be nested
109
/// within blocks, `if`s, or `else`s.
110
///
111
/// `BSLA_FORMAT(FMT_IDX)`:
112
/// This annotation specifies that the so-annotated function takes an
113
/// argument that is a valid format string for a `printf`-style function
114
/// and returns a format string that is consistent with that format. This
115
/// allows format strings manipulated by translation functions to be
116
/// checked against arguments. Without this annotation, attempting to
117
/// manipulate the format string via this kind of function might generate
118
/// warnings about non-literal formats, or fail to generate warnings about
119
/// mismatched arguments.
120
///
121
/// `BSLA_MAYBE_UNUSED`:
122
/// This annotation indicates that the so-annotated function, variable, or
123
/// type is possibly unused and the compiler should not generate a warning
124
/// for the unused identifier.
125
///
126
/// `BSLA_NODISCARD`:
127
/// This annotation causes a warning to be emitted if the caller of a
128
/// so-annotated function does not use its return value. This is useful
129
/// for functions where not checking the result is either a security
130
/// problem or always a bug, such as with the `realloc` function.
131
///
132
/// `BSLA_NONNULLARGS`:
133
/// This annotation indicates that a compiler warning is to be issued if
134
/// any of the pointer arguments to this function are passed null.
135
///
136
/// `BSLA_NONNULLARG(...)`:
137
/// This annotation, passed a variable-length list of positive integers,
138
/// indicates that a compiler warning is to be issued if null is passed to
139
/// a pointer argument at any of the specified indices, where the first
140
/// argument of the annotated function has an index of 1.
141
///
142
/// `BSLA_NORETURN`:
143
/// This annotation is used to tell the compiler that a specified function
144
/// will not return in a normal fashion. The function can still exit via
145
/// other means such as throwing an exception or aborting the process.
146
///
147
/// `BSLA_NULLTERMINATED`:
148
/// This annotation on a variadic macro indicates that a warning should be
149
/// issued unless the last argument to the function is explicitly `NULL`.
150
///
151
/// `BSLA_NULLTERMINATEDAT(ARG_IDX)`:
152
/// This annotation on a variadic function indicates that a warning should
153
/// be issued unless the argument at `ARG_IDX` is `NULL`, where `ARG_IDX`
154
/// is the number of arguments from the last, the last argument having
155
/// `ARG_IDX == 0`. Thus, `BSLA_NULLTERMINATED` is equivalent to
156
/// `BSLA_NULLTERMINATEDAT(0)`.
157
///
158
/// `BSLA_PRINTF(FMTIDX, STARTIDX)`:
159
/// This annotation instructs the compiler to perform additional
160
/// compile-time checks on so-annotated functions that take `printf`-style
161
/// arguments, which should be type-checked against a format string. The
162
/// `FMTIDX` parameter is the one-based index to the `const char *` format
163
/// string. The `STARTIDX` parameter is the one-based index to the first
164
/// variable argument to type-check against that format string. For
165
/// example:
166
/// @code
167
/// extern int my_printf(void *obj, const char *format, ...) BSLA_PRINTF(2, 3);
168
/// @endcode
169
///
170
/// `BSLA_SCANF(FMTIDX, STARTIDX)`:
171
/// This annotation instructs the compiler to perform additional checks on
172
/// so-annotated functions that take `scanf`-style arguments, which should
173
/// be type-checked against a format string.
174
///
175
/// The `FMTIDX` parameter is the one-based index to the `const` format
176
/// string. The `STARTIDX` parameter is the one-based index to the first
177
/// variable argument to type-check against that format string. For
178
/// example:
179
/// @code
180
/// extern int my_scanf(void *obj, const char *format, ...) BSLA_SCANF(2, 3);
181
/// @endcode
182
///
183
/// `BSLA_UNREACHABLE`:
184
/// This annotation will, when used, indicate that a given statement in a
185
/// code path is intended to be unreachable, causing compilers, where
186
/// supported, to issue warnings if there is actually a way that the code
187
/// can be reached. Note that the behavior is undefined if control
188
/// actually reaches a `BSLA_UNREACHABLE` statement.
189
///
190
/// `BSLA_UNUSED`:
191
/// This annotation indicates that the so-annotated function, variable, or
192
/// type is possibly unused and the compiler should not generate a warning
193
/// for the unused identifier.
194
///
195
/// `BSLA_USED`:
196
/// This annotation indicates that the so-annotated function, variable, or
197
/// type must be emitted even if it appears that the variable is not
198
/// referenced.
199
///
200
/// `BSLA_WARNING(QUOTED_MESSAGE)`:
201
/// This annotation, when used, will cause a compile-time warning
202
/// containing the specified `QUOTED_MESSAGE`, which must be a string
203
/// contained in double quotes, when a call to the so-annotated function is
204
/// not removed through dead-code elimination or other optimizations.
205
/// While it is possible to leave the function undefined, thus incurring a
206
/// link-time failure, with the use of this macro the invalid call will be
207
/// diagnosed earlier (i.e., at compile time), and the diagnostic will
208
/// include the location of the function call.
209
///
210
/// `BSLA_DEPRECATED_IS_ACTIVE`
211
/// `BSLA_ERROR_IS_ACTIVE`
212
/// `BSLA_FALLTHROUGH_IS_ACTIVE`
213
/// `BSLA_FORMAT_IS_ACTIVE`
214
/// `BSLA_MAYBE_UNUSED_IS_ACTIVE`
215
/// `BSLA_NODISCARD_IS_ACTIVE`
216
/// `BSLA_NONNULLARG_IS_ACTIVE`
217
/// `BSLS_NONNULLARGS_IS_ACTIVE`
218
/// `BSLA_NORETURN_IS_ACTIVE`
219
/// `BSLA_NULLTERMINATED_IS_ACTIVE`
220
/// `BSLA_NULLTERMINATEDAT_IS_ACTIVE`
221
/// `BSLA_PRINTF_IS_ACTIVE`
222
/// `BSLA_SCANF_IS_ACTIVE`
223
/// `BSLA_UNREACHABLE_IS_ACTIVE`
224
/// `BSLA_UNUSED_IS_ACTIVE`
225
/// `BSLA_USED_IS_ACTIVE`
226
/// `BSLA_WARNING_IS_ACTIVE`:
227
/// For each `BSLA_{X}` macro, there is a `BSLA_{X}_IS_ACTIVE` macro that
228
/// is defined only if `BSLA_{X}` expands to something and has its
229
/// documented effects.
230
///
231
/// ## Usage {#bsla_annotations-usage}
232
///
233
///
234
/// See the other `bsla` components for usage examples for the macros offered
235
/// (transitively) by this component.
236
/// @}
237
/** @} */
238
/** @} */
239
240
/** @addtogroup bsl
241
* @{
242
*/
243
/** @addtogroup bsla
244
* @{
245
*/
246
/** @addtogroup bsla_annotations
247
* @{
248
*/
249
250
#include <bsla_deprecated.h>
251
#include <
bsla_error.h
>
252
#include <
bsla_fallthrough.h
>
253
#include <
bsla_format.h
>
254
#include <
bsla_maybeunused.h
>
255
#include <
bsla_nodiscard.h
>
256
#include <
bsla_nonnullarg.h
>
257
#include <
bsla_noreturn.h
>
258
#include <
bsla_nullterminated.h
>
259
#include <
bsla_printf.h
>
260
#include <
bsla_scanf.h
>
261
#include <
bsla_unreachable.h
>
262
#include <
bsla_unused.h
>
263
#include <
bsla_used.h
>
264
#include <
bsla_warning.h
>
265
266
// BDE_VERIFY pragma: re-export <bsla_deprecated.h>
267
// BDE_VERIFY pragma: re-export <bsla_error.h>
268
// BDE_VERIFY pragma: re-export <bsla_fallthrough.h>
269
// BDE_VERIFY pragma: re-export <bsla_format.h>
270
// BDE_VERIFY pragma: re-export <bsla_maybeunused.h>
271
// BDE_VERIFY pragma: re-export <bsla_nodiscard.h>
272
// BDE_VERIFY pragma: re-export <bsla_nonnullarg.h>
273
// BDE_VERIFY pragma: re-export <bsla_noreturn.h>
274
// BDE_VERIFY pragma: re-export <bsla_nullterminated.h>
275
// BDE_VERIFY pragma: re-export <bsla_printf.h>
276
// BDE_VERIFY pragma: re-export <bsla_scanf.h>
277
// BDE_VERIFY pragma: re-export <bsla_unreachable.h>
278
// BDE_VERIFY pragma: re-export <bsla_unused.h>
279
// BDE_VERIFY pragma: re-export <bsla_used.h>
280
// BDE_VERIFY pragma: re-export <bsla_warning.h>
281
282
#endif
283
284
// ----------------------------------------------------------------------------
285
// Copyright 2019 Bloomberg Finance L.P.
286
//
287
// Licensed under the Apache License, Version 2.0 (the "License");
288
// you may not use this file except in compliance with the License.
289
// You may obtain a copy of the License at
290
//
291
// http://www.apache.org/licenses/LICENSE-2.0
292
//
293
// Unless required by applicable law or agreed to in writing, software
294
// distributed under the License is distributed on an "AS IS" BASIS,
295
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
296
// See the License for the specific language governing permissions and
297
// limitations under the License.
298
// ----------------------------- END-OF-FILE ----------------------------------
299
300
/** @} */
301
/** @} */
302
/** @} */
bsla_error.h
bsla_fallthrough.h
bsla_format.h
bsla_maybeunused.h
bsla_nodiscard.h
bsla_nonnullarg.h
bsla_noreturn.h
bsla_nullterminated.h
bsla_printf.h
bsla_scanf.h
bsla_unreachable.h
bsla_unused.h
bsla_used.h
bsla_warning.h
bsls_ident.h
BSLS_IDENT
#define BSLS_IDENT(str)
Definition
bsls_ident.h:195
doxygen_input
bde
groups
bsl
bsla
bsla_annotations.h
Generated by
1.9.8