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