BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bsla_deprecated.h
Go to the documentation of this file.
1
/// @file bsla_deprecated.h
2
///
3
/// The content of this file has been pre-processed for Doxygen.
4
///
5
6
7
// bsla_deprecated.h -*-C++-*-
8
#ifndef INCLUDED_BSLA_DEPRECATED
9
#define INCLUDED_BSLA_DEPRECATED
10
11
#include <
bsls_ident.h
>
12
BSLS_IDENT
(
"$Id: $"
)
13
14
/// @defgroup bsla_deprecated bsla_deprecated
15
/// @brief Provide compiler-hint macros to indicate deprecated entities.
16
/// @addtogroup bsl
17
/// @{
18
/// @addtogroup bsla
19
/// @{
20
/// @addtogroup bsla_deprecated
21
/// @{
22
///
23
/// <h1> Outline </h1>
24
/// * <a href="#bsla_deprecated-purpose"> Purpose</a>
25
/// * <a href="#bsla_deprecated-macros"> Macros </a>
26
/// * <a href="#bsla_deprecated-description"> Description </a>
27
/// * <a href="#bsla_deprecated-macro-reference"> Macro Reference </a>
28
/// * <a href="#bsla_deprecated-usage"> Usage </a>
29
/// * <a href="#bsla_deprecated-example-1-various-deprecations"> Example 1: Various Deprecations </a>
30
/// * <a href="#bsla_deprecated-define-bsla_deprecated"> define BSLA_DEPRECATED [[deprecated]] </a>
31
///
32
/// # Purpose {#bsla_deprecated-purpose}
33
/// Provide compiler-hint macros to indicate deprecated entities.
34
///
35
/// # Macros {#bsla_deprecated-macros}
36
///
37
/// - BSLA_DEPRECATED: warn if annotated (deprecated) entity is used
38
/// - BSLA_DEPRECATED_MESSAGE: warn with message if annotated entity is used
39
/// - BSLA_DEPRECATED_IS_ACTIVE: defined if both macros are active
40
///
41
/// @see bsla_annotations
42
///
43
/// # Description {#bsla_deprecated-description}
44
/// This component provides preprocessor macros that hint to the
45
/// compiler that a function, variable, type, `typedef`, `struct` member, `enum`
46
/// type, or template specialization is deprecated. This is useful, for
47
/// example, when identifying functions that are expected to be removed in a
48
/// future version of a library.
49
///
50
/// ## Macro Reference {#bsla_deprecated-macro-reference}
51
///
52
///
53
/// `BSLA_DEPRECATED`:
54
/// This annotation will, when used, cause a compile-time warning if the
55
/// so-annotated function, variable, type, `typedef`, `struct` member,
56
/// `enum` type, or template specialization is used anywhere within the
57
/// source file. The warning includes the location of the declaration of
58
/// the deprecated entity to enable users to find further information about
59
/// the deprecation, or what they should use instead.
60
///
61
/// `BSLA_DEPRECATED_MESSAGE(QUOTED_MESSAGE)`:
62
/// This annotation will, when used, cause a compile-time warning if the
63
/// so-annotated function, variable, type, `typedef`, `struct` member,
64
/// `enum` type, or template specialization is used anywhere within the
65
/// source file. The compiler warning will contain the contents of the
66
/// specified `QUOTED_MESSAGE`, which must be a double-quoted string. The
67
/// warning includes the location of the declaration of the deprecated
68
/// entity to enable users to find further information about the
69
/// deprecation, and what they should use instead. Note that on some
70
/// compilers `QUOTED_MESSAGE` is ignored.
71
///
72
/// `BSLA_DEPRECATED_IS_ACTIVE`:
73
/// The macro `BSLA_DEPRECATED_IS_ACTIVE` is defined if `BSLA_DEPRECATED` and
74
/// `BSLA_DEPRECATED_MESSAGE` are both active and have the desired effect;
75
/// otherwise, `BSLA_DEPRECATED_IS_ACTIVE` is not defined and both other
76
/// macros expand to nothing.
77
///
78
/// ## Usage {#bsla_deprecated-usage}
79
///
80
///
81
/// This section illustrates intended use of this component.
82
///
83
/// ### Example 1: Various Deprecations {#bsla_deprecated-example-1-various-deprecations}
84
///
85
///
86
/// First, we define a deprecated type `UsageType`:
87
/// @code
88
/// struct BSLA_DEPRECATED UsageType {
89
/// int d_int;
90
/// };
91
/// @endcode
92
/// Then, we define a function `usageFunc` that is deprecated:
93
/// @code
94
/// BSLA_DEPRECATED
95
/// void usageFunc();
96
/// void usageFunc()
97
/// {
98
/// printf("Don't call me.\n");
99
/// }
100
/// @endcode
101
/// Next, we define a variable `usageVar` that is deprecated:
102
/// @code
103
/// BSLA_DEPRECATED extern int usageVar;
104
/// int usageVar = 5;
105
/// @endcode
106
/// Then, we define a typedef `UsageTypedef` that is deprecated:
107
/// @code
108
/// BSLA_DEPRECATED typedef int UsageTypedef;
109
/// @endcode
110
/// Next, we define a `struct` with a member `d_y` that is deprecated:
111
/// @code
112
/// struct UsageStruct {
113
/// double d_x;
114
/// BSLA_DEPRECATED double d_y;
115
/// };
116
/// @endcode
117
/// Then, we define an `enum` `UsageEnum` that is deprecated:
118
/// @code
119
/// enum BSLA_DEPRECATED UsageEnum { e_FALSE, e_TRUE };
120
/// @endcode
121
/// Next, we define a template this is only deprecated in the case where it is
122
/// specialized with the `int` type as a template parameter:
123
/// @code
124
/// template <class TYPE>
125
/// TYPE usageAbs(TYPE x)
126
/// {
127
/// return x < 0 ? -x : x;
128
/// }
129
///
130
/// template <>
131
/// BSLA_DEPRECATED_MESSAGE("'int' specialization not allowed")
132
/// int usageAbs<int>(int x)
133
/// {
134
/// int ret = x < 0 ? -x : x;
135
/// return ret < 0 ? ~ret : ret;
136
/// }
137
/// @endcode
138
/// Then, as long as we don't use them, no warnings will be issued.
139
///
140
/// Next, we use `UsageType`:
141
/// @code
142
/// UsageType ut;
143
/// ut.d_int = 5;
144
/// (void) ut.d_int;
145
/// @endcode
146
/// which results in the following warnings:
147
/// @code
148
/// .../bsla_deprecated.t.cpp:287:5: warning: 'UsageType' is deprecated
149
/// [-Wdeprecated-declarations]
150
/// UsageType ut;
151
/// ^
152
/// .../bsla/bsla_deprecated.t.cpp:113:7: note: 'UsageType' has been explicitly
153
/// marked deprecated here
154
/// } BSLA_DEPRECATED;
155
/// ^
156
/// @endcode
157
/// Then, we call `usageFunc`:
158
/// @code
159
/// usageFunc();
160
/// @endcode
161
/// which results in the following warnings:
162
/// @code
163
/// .../bsla_deprecated.t.cpp:309:5: warning: 'usageFunc' is deprecated
164
/// [-Wdeprecated-declarations]
165
/// usageFunc();
166
/// ^
167
/// .../bsla_deprecated.t.cpp:117:22: note: 'usageFunc' has been explicitly
168
/// marked deprecated here
169
/// void usageFunc() BSLA_DEPRECATED;
170
/// ^
171
/// @endcode
172
/// Next, we access `usageVar`:
173
/// @code
174
/// printf("%d\n", usageVar);
175
/// @endcode
176
/// which results in the following warnings:
177
/// @code
178
/// .../bsla_deprecated.t.cpp:326:20: warning: 'usageVar' is deprecated
179
/// [-Wdeprecated-declarations]
180
/// printf("%d\n", usageVar);
181
/// ^
182
/// .../bsla_deprecated.t.cpp:134:25: note: 'usageVar' has been explicitly
183
/// marked deprecated here
184
/// extern int usageVar BSLA_DEPRECATED;
185
/// ^
186
/// .../bsla_deprecated.h:119:32: note: expanded from macro 'BSLA_DEPRECATED'
187
/// # define BSLA_DEPRECATED [[deprecated]] {#bsla_deprecated-define-bsla_deprecated}
188
///
189
/// @endcode
190
/// Then, we use `UsageTypedef`:
191
/// @code
192
/// UsageTypedef jjj = 32;
193
/// (void) jjj;
194
/// @endcode
195
/// which results in the following warnings:
196
/// @code
197
/// .../bsla_deprecated.t.cpp:379:5: warning: 'UsageTypedef' is deprecated
198
/// [-Wdeprecated-declarations]
199
/// UsageTypedef jjj = 32;
200
/// ^
201
/// .../bsla_deprecated.t.cpp:140:5: note: 'UsageTypedef' has been explicitly
202
/// marked deprecated here
203
/// BSLA_DEPRECATED typedef int UsageTypedef;
204
/// ^
205
/// @endcode
206
/// Next, we access the deprecated member of `UsageStruct`:
207
/// @code
208
/// UsageStruct us;
209
/// ::memset(&us, 0, sizeof(us));
210
/// assert(0 == us.d_x); // no warning
211
/// assert(0 == us.d_y); // 'd_y' is deprecated -- issues warning.
212
/// @endcode
213
/// which results in the following warnings:
214
/// @code
215
/// .../bsla_deprecated.t.cpp:387:20: warning: 'd_y' is deprecated
216
/// [-Wdeprecated-declarations]
217
/// assert(0 == us.d_y); // 'd_y' is deprecated -- issues warning.
218
/// ^
219
/// .../bsla_deprecated.t.cpp:146:9: note: 'd_y' has been explicitly marked
220
/// deprecated here
221
/// BSLA_DEPRECATED double d_y;
222
/// ^
223
/// @endcode
224
/// Now, we use the deprecated `UsageEnum`:
225
/// @code
226
/// UsageEnum ue;
227
/// ue = e_TRUE;
228
/// (void) ue;
229
/// @endcode
230
/// which results in the following warnings:
231
/// @code
232
/// .../bsla_deprecated.t.cpp:411:15: warning: 'UsageEnum' is deprecated
233
/// [-Wdeprecated-declarations]
234
/// UsageEnum ue;
235
/// ^
236
/// .../bsla_deprecated.t.cpp:152:26: note: declared here
237
/// enum BSLA_DEPRECATED UsageEnum { e_FALSE, e_TRUE };
238
/// ^
239
/// @endcode
240
/// Finally, we access the deprecated specialization of `usageAbs`:
241
/// @code
242
/// assert(2.0 == usageAbs(-2.0)); // no warning, 'usageAbs<double>'
243
/// // not deprecated
244
/// assert(INT_MAX == usageAbs(INT_MIN)); // warning, 'usageAbs<int>' is
245
/// // deprecated
246
/// @endcode
247
/// which results in the following warnings:
248
/// @code
249
/// .../bsla_deprecated.t.cpp:441:39: warning: 'TYPE usageAbs(TYPE) [with TYPE
250
/// = int]' is deprecated: 'int' specialization not allowed
251
/// [-Wdeprecated-declarations]
252
/// assert(INT_MAX == usageAbs(INT_MIN)); // warning, 'usageAbs<int>'
253
/// ^
254
/// .../bsla_deprecated.t.cpp:168:9: note: declared here
255
/// int usageAbs<int>(int x)
256
/// ^~~~~~~~~~~~~
257
/// @endcode
258
/// @}
259
/** @} */
260
/** @} */
261
262
/** @addtogroup bsl
263
* @{
264
*/
265
/** @addtogroup bsla
266
* @{
267
*/
268
/** @addtogroup bsla_deprecated
269
* @{
270
*/
271
272
#include <bsls_platform.h>
273
274
// =============================
275
// Checks for Pre-Defined macros
276
// =============================
277
278
#if defined(BSLA_DEPRECATED)
279
#error BSLA_DEPRECATED is already defined!
280
#endif
281
282
#if defined(BSLA_DEPRECATED_MESSAGE)
283
#error BSLA_DEPRECATED_MESSAGE is already defined!
284
#endif
285
286
#if defined(BSLA_DEPRECATED_IS_ACTIVE)
287
#error BSLA_DEPRECATED_IS_ACTIVE is already defined!
288
#endif
289
290
// =========================
291
// Set macros as appropriate
292
// =========================
293
294
#if (defined(BSLS_PLATFORM_CMP_GNU) || defined(BSLS_PLATFORM_CMP_CLANG)) && \
295
defined(__has_cpp_attribute)
296
# if __has_attribute(deprecated)
297
# if 201402L <= __cplusplus || \
298
(defined(BSLS_PLATFORM_CMP_GNU) && 201103L <= __cplusplus)
299
# define BSLA_DEPRECATED [[ deprecated ]]
300
# define BSLA_DEPRECATED_MESSAGE(message) [[ deprecated(message) ]]
301
# else
302
# define BSLA_DEPRECATED __attribute__((__deprecated__))
303
# define BSLA_DEPRECATED_MESSAGE(message) __attribute__((__deprecated__))
304
# endif
305
306
# define BSLA_DEPRECATED_IS_ACTIVE 1
307
# endif
308
#else
309
# define BSLA_DEPRECATED
310
# define BSLA_DEPRECATED_MESSAGE(message)
311
#endif
312
313
#endif
314
315
// ----------------------------------------------------------------------------
316
// Copyright 2019 Bloomberg Finance L.P.
317
//
318
// Licensed under the Apache License, Version 2.0 (the "License");
319
// you may not use this file except in compliance with the License.
320
// You may obtain a copy of the License at
321
//
322
// http://www.apache.org/licenses/LICENSE-2.0
323
//
324
// Unless required by applicable law or agreed to in writing, software
325
// distributed under the License is distributed on an "AS IS" BASIS,
326
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
327
// See the License for the specific language governing permissions and
328
// limitations under the License.
329
// ----------------------------- END-OF-FILE ----------------------------------
330
331
/** @} */
332
/** @} */
333
/** @} */
bsls_ident.h
BSLS_IDENT
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition
bsls_ident.h:238
doxygen_input
bde
groups
bsl
bsla
bsla_deprecated.h
Generated by
1.9.8