BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsls_deprecatefeature.h
Go to the documentation of this file.
1
/// @file bsls_deprecatefeature.h
2
///
3
/// The content of this file has been pre-processed for Doxygen.
4
///
5
6
7
// bsls_deprecatefeature.h -*-C++-*-
8
#ifndef INCLUDED_BSLS_DEPRECATEFEATURE
9
#define INCLUDED_BSLS_DEPRECATEFEATURE
10
11
/// @defgroup bsls_deprecatefeature bsls_deprecatefeature
12
/// @brief Provide machinery to deprecate entities in C++ code.
13
/// @addtogroup bsl
14
/// @{
15
/// @addtogroup bsls
16
/// @{
17
/// @addtogroup bsls_deprecatefeature
18
/// @{
19
///
20
/// <h1> Outline </h1>
21
/// * <a href="#bsls_deprecatefeature-purpose"> Purpose</a>
22
/// * <a href="#bsls_deprecatefeature-macros"> Macros </a>
23
/// * <a href="#bsls_deprecatefeature-description"> Description </a>
24
/// * <a href="#bsls_deprecatefeature-concerns-with-compiler-warnings"> Concerns with Compiler Warnings </a>
25
/// * <a href="#bsls_deprecatefeature-macro-reference"> Macro Reference </a>
26
/// * <a href="#bsls_deprecatefeature-configuration-reference"> Configuration Reference </a>
27
/// * <a href="#bsls_deprecatefeature-usage"> Usage </a>
28
/// * <a href="#bsls_deprecatefeature-example-1-deprecating-a-feature"> Example 1: Deprecating a Feature </a>
29
/// * <a href="#bsls_deprecatefeature-deprecating-a-feature-across-multiple-headers"> Deprecating a Feature Across Multiple Headers </a>
30
///
31
/// # Purpose {#bsls_deprecatefeature-purpose}
32
/// Provide machinery to deprecate entities in C++ code.
33
///
34
/// # Macros {#bsls_deprecatefeature-macros}
35
///
36
/// - BSLS_DEPRECATE_FEATURE: mark a C++ entity as deprecated
37
///
38
/// # Description {#bsls_deprecatefeature-description}
39
/// This component provides facilities to identify deprecated C++
40
/// entities. The deprecation annotations supplied by this component may,
41
/// depending on the build configuration, instantiate as C++ `[[deprecated]]`
42
/// annotations for which the compiler will emit a warning. Each deprecated
43
/// entity annotated by the macros in this component is identified by a `UOR`
44
/// and `FEATURE`, allowing the use of that deprecated entity to be more easily
45
/// uniquely identified and tracked over time via tooling. Here "UOR" means
46
/// Unit-Of-Release, which is typically a package, package-group or library.
47
///
48
/// **WARNING**: The build configuration flag,
49
/// `BB_DEPRECATE_ENABLE_ALL_DEPRECATIONS_FOR_TESTING`, that enables compiler
50
/// warnings for `BSLS_DEPRECATE_FEATURE` should not be used in
51
/// cross-organizational integration builds such as a production `unstable`
52
/// dpkg build.
53
///
54
/// ## Concerns with Compiler Warnings {#bsls_deprecatefeature-concerns-with-compiler-warnings}
55
///
56
///
57
/// In large development organization, where many teams may enable "warnings as
58
/// errors", enabling deprecation warnings in a cross-organizational integration
59
/// build will frequently prevent lower-level software from applying the
60
/// deprecation annotation to any newly deprecated code.
61
///
62
/// Instead this component is designed to support static analysis tools that
63
/// identify deprecated entities, and allow them to be tracked and reported by
64
/// systems outside of the normal compilation process. The expectation is that
65
/// developers would use configuration options that generate compiler warnings
66
/// in local builds when they are actively working to remove the use of
67
/// deprecated code.
68
///
69
/// ## Macro Reference {#bsls_deprecatefeature-macro-reference}
70
///
71
///
72
/// This section documents the preprocessor macros defined in this component.
73
///
74
/// * `BSLS_DEPRECATE_FEATURE(UOR, FEATURE, MESSAGE)`
75
/// > This macro is used to annotate code to indicate that a name or entity
76
/// > has been deprecated, and is associated with the specified `UOR`
77
/// > (Unit-Of-Release), deprecated `FEATURE`, and `MESSAGE`. This macro can
78
/// > be used as if it were the C++ standard attribute `[[deprecated]]`, and
79
/// > in appropriate build configurations will instantiate as a C++
80
/// > `[[deprecated]]` annotation. `UOR` and `FEATURE` are character strings
81
/// > intended to uniquely identify one or more related entities that have
82
/// > been deprecated. `MESSAGE` is a descriptive text intended for the a
83
/// > user of the deprecated feature (for example informing them of a
84
/// > replacement feature). For example, if several of the date and time
85
/// > types in the `bde` library were deprecated they might be marked with the
86
/// > annotation:
87
/// > `BSLS_DEPRECATE_FEATURE("bde", "date-and-time", "Use bdlt instead")`.
88
/// > `UOR` and `FEATURE` are meant to help uniquely identify a deprecation in
89
/// > external systems (e.g., a dashboard monitoring the state of a
90
/// > deprecation) so the supplied strings should start with a letter, and
91
/// > contain only letters, numbers, underscore, and dash characters (i.e.,
92
/// > matching the regular expression "[a-zA-Z][\w\-]*").
93
///
94
/// * `BSLS_DEPRECATE_FEATURE_IS_SUPPORTED`
95
/// > This macro is defined if the current platform supports instantiating the
96
/// > deprecation annotation macros into annotation understood by the
97
/// > compiler.
98
///
99
/// * `BSLS_DEPRECATE_FEATURE_ANNOTATION_IS_ACTIVE`
100
/// > This macro is defined if deprecation annotation macros defined in this
101
/// > component *will* be instantiated into annotations understood by the
102
/// > compiler (i.e., this will be defined if
103
/// > `BSLS_DEPRECATE_FEATURE_SUPPORTED_PLATFORM` is defined and the build
104
/// > configuration macros are configured in a way that the annotations will
105
/// > instantiate as the `[[deprecated]]` attribute).
106
///
107
/// ## Configuration Reference {#bsls_deprecatefeature-configuration-reference}
108
///
109
///
110
/// There are a set of macros, not defined by this component, that users may
111
/// supply (e.g., to their build system) to configure the behavior of the
112
/// deprecation annotation macros provided by this component.
113
///
114
/// The available configuration macros are described below:
115
/// * `BB_DEPRECATE_ENABLE_ALL_DEPRECATIONS_FOR_TESTING`
116
/// > This macro, when
117
/// > defined, enables the instantiation of every deprecation macro as a C++
118
/// > `[[deprecated]]` annotation. This *MUST* *NOT* be defined as part of
119
/// > cross-organization integration build such as an 'unstable' dpkg build
120
/// > (see {Concerns with Compiler Warnings}).
121
///
122
/// * `BB_DEPRECATE_ENABLE_JSON_MESSAGE`
123
/// > Changes the messages reported by compiler deprecation annotations to be
124
/// > a JSON document intended to be useful for tools looking to identify and
125
/// > categorize deprecations.
126
///
127
/// * `BSLS_DEPRECATE_FEATURE_ENABLE_ALL_DEPRECATIONS_FOR_TESTING`
128
/// > This macro is a synonym for
129
/// > `BB_DEPRECATE_ENABLE_ALL_DEPRECATIONS_FOR_TESTING`.
130
///
131
/// * `BSLS_DEPRECATE_FEATURE_ENABLE_JSON_MESSAGE`
132
/// > This macro is a synonym for `BB_DEPRECATE_ENABLE_JSON_MESSAGE`.
133
///
134
/// ## Usage {#bsls_deprecatefeature-usage}
135
///
136
///
137
/// In this section we show intended usage of this component.
138
///
139
/// ### Example 1: Deprecating a Feature {#bsls_deprecatefeature-example-1-deprecating-a-feature}
140
///
141
///
142
/// The following example demonstrates using the `BSLS_DEPRECATE_FEATURE` macro
143
/// to deprecate several C++ entities.
144
///
145
/// The `BSLS_DEPRECATE_FEATURE` macro can be applied in the same way as the C++
146
/// `[[deprecated]]` annotation. For example, imagine we are deprecating a
147
/// function `oldFunction` in the `bsl` library as part of migrating software to
148
/// the linux platform, we might write:
149
/// @code
150
/// BSLS_DEPRECATE_FEATURE("bsl", "oldFunction", "Use newFunction instead")
151
/// void oldFunction();
152
/// @endcode
153
/// Here the string "bsl" refers to the library or Unit-Of-Release (UOR) that
154
/// the deprecation occurs in. "oldFunction" is an arbitrary identifier for
155
/// the feature being deprecated. Together the `UOR` and `FEATURE` are
156
/// intended to form a unique enterprise-wide identifier for the feature being
157
/// deprecated. Finally the string "Use newFunction instead" is a message for
158
/// users of the deprecated feature.
159
///
160
/// Marking `oldFunction` in this way makes the deprecation of `oldFunction`
161
/// visible to code analysis tools. In addition, in a local build, warnings
162
/// for uses of the deprecated entity can be enabled using a build macro
163
/// `BB_DEPRECATE_ENABLE_ALL_DEPRECATIONS_FOR_TESTING` (this macro *MUST* *NOT*
164
/// be used as part of a cross-organization integration build such as a
165
/// `unstable` dpkg build, see {Concerns with Compiler Warnings}).
166
///
167
/// Similarly, if we were deprecating a class `OldType` we might write:
168
/// @code
169
///
170
/// /// ...
171
/// class BSLS_DEPRECATE_FEATURE("bsl", "OldType", "Use NewType instead")
172
/// OldType {
173
/// };
174
/// @endcode
175
/// Frequently, more than one C++ related entity may be associated with a
176
/// deprecated feature. In that case we would want to use the same identifier
177
/// for each entity we mark deprecated. To simplify this we might create a
178
/// deprecation macro that is local to the component. For example, if we were
179
/// deprecating a queue and its iterator in the `bde` library we might write:
180
/// @code
181
/// #define BDEC_QUEUE_DEPRECATE \.
182
/// BSLS_DEPRECATE_FEATURE("bde", "bdec_queue", "Use bsl::queue instead")
183
///
184
/// /// ...
185
/// class BDEC_QUEUE_DEPRECATE bdec_Queue {
186
/// };
187
///
188
/// /// ...
189
/// class BDEC_QUEUE_DEPRECATE bdec_QueueIterator {
190
/// };
191
/// @endcode
192
/// Sometimes several entities are deprecated as part of the same feature where
193
/// separate messages are appropriate. For example, imagine we had a component
194
/// @ref bsls_measurementutil that we were converting from imperial to metric
195
/// units:
196
/// @code
197
/// #define BSLS_MEASUREMEANTUTIL_DEPRECATE_IMPERIAL(MESSAGE) \.
198
/// BSLS_DEPRECATE_FEATURE("bsl", "deprecate-imperial-units", MESSAGE)
199
///
200
/// struct MeasurementUtil {
201
///
202
/// BSLS_MEASUREMEANTUTIL_DEPRECATE_IMPERIAL("Use getKilometers instead")
203
/// static double getMiles();
204
///
205
/// BSLS_MEASUREMEANTUTIL_DEPRECATE_IMPERIAL("Use getKilograms instead")
206
/// static double getPounds();
207
/// };
208
/// @endcode
209
///
210
/// ### Deprecating a Feature Across Multiple Headers {#bsls_deprecatefeature-deprecating-a-feature-across-multiple-headers}
211
///
212
///
213
/// Frequently a feature being deprecated may span multiple components. For
214
/// example, we may want to deprecate all the date and time types in the `bde`
215
/// library. In those instances one may define a macro in the lowest level
216
/// component (e.g., define `BDET_DATE_DEPRECATE_DATE_AND_TIME` in @ref bdet_date ).
217
/// Alternatively, one might create a component specifically for the deprecation
218
/// (e.g., define `BDET_DEPRECATE_DATE_AND_TIME` in a newly created
219
/// @ref bdet_deprecate component). The following code shows the latter, creating
220
/// a new component, @ref bdet_deprecate in which to provide macros to deprecate
221
/// code across `bdet`.
222
///
223
/// First, we create a new component, @ref bdet_deprecate and define the following
224
/// macro:
225
/// @code
226
/// // bdet_deprecate.h
227
///
228
/// #define BDET_DEPRECATE_DATE_AND_TIME(MESSAGE) \.
229
/// BSLS_DEPRECATE_FEATURE("bde", "date-and-time", MESSAGE)
230
/// @endcode
231
/// We can use that macro to mark various components deprecated. Next, we mark
232
/// an old type name as deprecated:
233
/// @code
234
/// // bdet_date.h
235
///
236
/// BDET_DEPRECATE_DATE_AND_TIME("Use bdlt::Date") typedef bdlt::Date Date;
237
/// @endcode
238
/// Then we mark a class declaration as deprecated:
239
/// @code
240
/// // bdet_calendar.h
241
///
242
/// /// ...
243
/// class BDET_DEPRECATE_DATE_AND_TIME("Use bdlt::PackedCalendar") Calendar {
244
/// };
245
/// @endcode
246
/// Finally we mark a function as deprecated:
247
/// @code
248
/// // bdet_dateimputil.h
249
///
250
/// struct DateUtil {
251
///
252
/// BDET_DEPRECATE_DATE_AND_TIME("Use bdlt::DateUtil instead")
253
/// static bool isValidYYYYMMDD(int yyyymmddValue);
254
///
255
/// // ...
256
/// };
257
/// @endcode
258
/// @}
259
/** @} */
260
/** @} */
261
262
/** @addtogroup bsl
263
* @{
264
*/
265
/** @addtogroup bsls
266
* @{
267
*/
268
/** @addtogroup bsls_deprecatefeature
269
* @{
270
*/
271
272
// ==============================
273
// Component Configuration Macros
274
// ==============================
275
276
// This could be replaced with BSLS_COMPILERFEATURES_CPLUSPLUS, but for the
277
// moment, this header has 0 dependencies, which may be a useful feature to
278
// maintain.
279
280
#if (defined(__cplusplus) && (__cplusplus >= 201703L)) || \
281
(defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))
282
#define BSLS_DEPRECATE_FEATURE_IS_SUPPORTED
283
#endif
284
285
#if defined(BSLS_DEPRECATE_FEATURE_IS_SUPPORTED) && \
286
(defined(BB_DEPRECATE_ENABLE_ALL_DEPRECATIONS_FOR_TESTING) || \
287
defined(BSLS_DEPRECATE_FEATURE_ENABLE_ALL_DEPRECATIONS_FOR_TESTING))
288
#define BSLS_DEPRECATE_FEATURE_ANNOTATION_IS_ACTIVE
289
#else
290
#undef BSLS_DEPRECATE_FEATURE_ANNOTATION_IS_ACTIVE
291
#endif
292
293
// ====================================
294
// Implementation Details: Do *NOT* Use
295
// ====================================
296
297
#ifndef BSLS_DEPRECATE_FEATURE_ANNOTATION_IS_ACTIVE
298
#define BSLS_DEPRECATE_FEATURE_IMP(UOR, FEATURE, MESSAGE)
299
#else
300
#if defined(BB_DEPRECATE_ENABLE_JSON_MESSAGE) || \
301
defined(BSLS_DEPRECATE_FEATURE_ENABLE_JSON_MESSAGE)
302
#define BSLS_DEPRECATE_FEATURE_IMP(UOR, FEATURE, MESSAGE) \
303
[[deprecated("{\"library\": \"" UOR "\", \"feature\": \"" FEATURE \
304
"\", \"message\": \"" MESSAGE "\"}")]]
305
#else
306
#define BSLS_DEPRECATE_FEATURE_IMP(UOR, FEATURE, MESSAGE) \
307
[[deprecated(MESSAGE)]]
308
#endif
// BB_DEPRECATE_ENABLE_JSON_MESSAGE
309
#endif
310
311
// If the number of arguments needs to be expanded, commit
312
// abd14c70a7c9fb38d9bf3fe225eb0966cb036c9f contains a variadic implementation
313
// similar to 'BSLIM_TESTUTIL_ASSERTV'.
314
315
// =================
316
// Annotation Macros
317
// =================
318
319
#define BSLS_DEPRECATE_FEATURE(UOR, FEATURE, MESSAGE) \
320
BSLS_DEPRECATE_FEATURE_IMP(UOR, FEATURE, MESSAGE)
321
322
#endif
// INCLUDED_BSLS_DEPRECATEFEATURE
323
324
// ----------------------------------------------------------------------------
325
// Copyright 2022 Bloomberg Finance L.P.
326
//
327
// Licensed under the Apache License, Version 2.0 (the "License");
328
// you may not use this file except in compliance with the License.
329
// You may obtain a copy of the License at
330
//
331
// http://www.apache.org/licenses/LICENSE-2.0
332
//
333
// Unless required by applicable law or agreed to in writing, software
334
// distributed under the License is distributed on an "AS IS" BASIS,
335
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
336
// See the License for the specific language governing permissions and
337
// limitations under the License.
338
// ----------------------------- END-OF-FILE ----------------------------------
339
340
/** @} */
341
/** @} */
342
/** @} */
doxygen_input
bde
groups
bsl
bsls
bsls_deprecatefeature.h
Generated by
1.9.8