BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsla_warning.h
Go to the documentation of this file.
1
/// @file bsla_warning.h
2
///
3
/// The content of this file has been pre-processed for Doxygen.
4
///
5
6
7
// bsla_warning.h -*-C++-*-
8
#ifndef INCLUDED_BSLA_WARNING
9
#define INCLUDED_BSLA_WARNING
10
11
#include <
bsls_ident.h
>
12
BSLS_IDENT
(
"$Id: $"
)
13
14
/// @defgroup bsla_warning bsla_warning
15
/// @brief Provide a macro to emit a warning when a function is called.
16
/// @addtogroup bsl
17
/// @{
18
/// @addtogroup bsla
19
/// @{
20
/// @addtogroup bsla_warning
21
/// @{
22
///
23
/// <h1> Outline </h1>
24
/// * <a href="#bsla_warning-purpose"> Purpose</a>
25
/// * <a href="#bsla_warning-macros"> Macros </a>
26
/// * <a href="#bsla_warning-description"> Description </a>
27
/// * <a href="#bsla_warning-macro-reference"> Macro Reference </a>
28
/// * <a href="#bsla_warning-usage"> Usage </a>
29
/// * <a href="#bsla_warning-example-1-function-annotated-with-bsla_warning"> Example 1: Function Annotated with BSLA_WARNING </a>
30
///
31
/// # Purpose {#bsla_warning-purpose}
32
/// Provide a macro to emit a warning when a function is called.
33
///
34
/// # Macros {#bsla_warning-macros}
35
///
36
/// - BSLA_WARNING(QUOTED_MESSAGE): emit warning message during compilation
37
/// - BSLA_WARNING_IS_ACTIVE: defined if `BSLA_WARNING` is active
38
///
39
/// @see bsla_annotations
40
///
41
/// # Description {#bsla_warning-description}
42
/// This component provides a macro that indicates that a compiler
43
/// warning should be emitted when a given function is called.
44
///
45
/// ## Macro Reference {#bsla_warning-macro-reference}
46
///
47
///
48
/// `BSLA_WARNING(QUOTED_MESSAGE)`:
49
/// This annotation, when used, will cause a compile-time warning
50
/// containing the specified `QUOTED_MESSAGE`, which must be a string
51
/// contained in double quotes, when a call to the so-annotated function is
52
/// not removed through dead-code elimination or other optimizations.
53
/// While it is possible to leave the function undefined, thus incurring a
54
/// link-time failure, with the use of this macro the invalid call will be
55
/// diagnosed earlier (i.e., at compile time), and the diagnostic will
56
/// include the location of the function call.
57
///
58
/// `BSLA_WARNING_IS_ACTIVE`:
59
/// The macro `BSLA_WARNING_IS_ACTIVE` is defined if `BSLA_WARNING` expands
60
/// to something with the desired effect; otherwise
61
/// `BSLA_WARNING_IS_ACTIVE` is not defined and `BSLA_WARNING` expands to
62
/// nothing.
63
///
64
/// ## Usage {#bsla_warning-usage}
65
///
66
///
67
/// This section illustrates intended use of this component.
68
///
69
/// ### Example 1: Function Annotated with BSLA_WARNING {#bsla_warning-example-1-function-annotated-with-bsla_warning}
70
///
71
///
72
/// First, we declare and define a function annotated with `BSLA_WARNING`. Note
73
/// that the argument to `BSLA_WARNING` must be a quoted string:
74
/// @code
75
/// /// Do nothing.
76
/// void usageFunc() BSLA_WARNING("Don't call 'usageFunc'");
77
///
78
/// void usageFunc()
79
/// {
80
/// }
81
/// @endcode
82
/// Now, in `main`, we call `usageFunc`:
83
/// @code
84
/// usageFunc();
85
/// @endcode
86
/// Finally, observe the following warning issued by the compiler:
87
/// @code
88
/// .../bsla_warning.t.cpp: In function 'int main(int, char**)':
89
/// .../bsla_warning.t.cpp:246:16: warning: call to 'usageFunc' declared with
90
/// attribute warning: Don't call 'usageFunc'
91
/// usageFunc();
92
/// ^
93
/// @endcode
94
/// @}
95
/** @} */
96
/** @} */
97
98
/** @addtogroup bsl
99
* @{
100
*/
101
/** @addtogroup bsla
102
* @{
103
*/
104
/** @addtogroup bsla_warning
105
* @{
106
*/
107
108
#include <bsls_platform.h>
109
110
// =============================
111
// Checks for Pre-Defined macros
112
// =============================
113
114
#if defined(BSLA_WARNING)
115
#error BSLA_WARNING is already defined!
116
#endif
117
118
#if defined(BSLA_WARNING_IS_ACTIVE)
119
#error BSLA_WARNING_IS_ACTIVE is already defined!
120
#endif
121
122
// =========================
123
// Set macros as appropriate
124
// =========================
125
126
#if defined(BSLS_PLATFORM_CMP_GNU)
127
// The '__warning__' attribute is not supported by clang as of version
128
// 8.0.0.
129
130
#define BSLA_WARNING(x) __attribute__((__warning__(x)))
131
132
#define BSLA_WARNING_IS_ACTIVE 1
133
#else
134
#define BSLA_WARNING(x)
135
#endif
136
137
#endif
138
139
// ----------------------------------------------------------------------------
140
// Copyright 2019 Bloomberg Finance L.P.
141
//
142
// Licensed under the Apache License, Version 2.0 (the "License");
143
// you may not use this file except in compliance with the License.
144
// You may obtain a copy of the License at
145
//
146
// http://www.apache.org/licenses/LICENSE-2.0
147
//
148
// Unless required by applicable law or agreed to in writing, software
149
// distributed under the License is distributed on an "AS IS" BASIS,
150
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
151
// See the License for the specific language governing permissions and
152
// limitations under the License.
153
// ----------------------------- END-OF-FILE ----------------------------------
154
155
/** @} */
156
/** @} */
157
/** @} */
bsls_ident.h
BSLS_IDENT
#define BSLS_IDENT(str)
Definition
bsls_ident.h:195
doxygen_input
bde
groups
bsl
bsla
bsla_warning.h
Generated by
1.9.8