1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* C++ compatible function declaration macros.
4 Copyright (C) 2010-2011 Free Software Foundation, Inc.
6 This program is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* The three most frequent use cases of these macros are:
24 * For providing a substitute for a function that is missing on some
25 platforms, but is declared and works fine on the platforms on which
30 _GL_FUNCDECL_SYS (foo, ...);
32 _GL_CXXALIAS_SYS (foo, ...);
33 _GL_CXXALIASWARN (foo);
34 #elif defined GNULIB_POSIXCHECK
38 * For providing a replacement for a function that exists on all platforms,
39 but is broken/insufficient and needs to be replaced on some platforms:
43 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
47 _GL_FUNCDECL_RPL (foo, ...);
48 _GL_CXXALIAS_RPL (foo, ...);
50 _GL_CXXALIAS_SYS (foo, ...);
52 _GL_CXXALIASWARN (foo);
53 #elif defined GNULIB_POSIXCHECK
57 * For providing a replacement for a function that exists on some platforms
58 but is broken/insufficient and needs to be replaced on some of them and
59 is additionally either missing or undeclared on some other platforms:
63 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
67 _GL_FUNCDECL_RPL (foo, ...);
68 _GL_CXXALIAS_RPL (foo, ...);
70 # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
71 _GL_FUNCDECL_SYS (foo, ...);
73 _GL_CXXALIAS_SYS (foo, ...);
75 _GL_CXXALIASWARN (foo);
76 #elif defined GNULIB_POSIXCHECK
81 /* _GL_EXTERN_C declaration;
82 performs the declaration with C linkage. */
83 #if defined __cplusplus
84 # define _GL_EXTERN_C extern "C"
86 # define _GL_EXTERN_C extern
89 /* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
90 declares a replacement function, named rpl_func, with the given prototype,
91 consisting of return type, parameters, and attributes.
93 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
94 _GL_ARG_NONNULL ((1)));
96 #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
97 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
98 #define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
99 _GL_EXTERN_C rettype rpl_func parameters_and_attributes
101 /* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
102 declares the system function, named func, with the given prototype,
103 consisting of return type, parameters, and attributes.
105 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
106 _GL_ARG_NONNULL ((1)));
108 #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
109 _GL_EXTERN_C rettype func parameters_and_attributes
111 /* _GL_CXXALIAS_RPL (func, rettype, parameters);
112 declares a C++ alias called GNULIB_NAMESPACE::func
113 that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
115 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
117 #define _GL_CXXALIAS_RPL(func,rettype,parameters) \
118 _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
119 #if defined __cplusplus && defined GNULIB_NAMESPACE
120 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
121 namespace GNULIB_NAMESPACE \
123 rettype (*const func) parameters = ::rpl_func; \
125 _GL_EXTERN_C int _gl_cxxalias_dummy
127 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
128 _GL_EXTERN_C int _gl_cxxalias_dummy
131 /* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
132 is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
133 except that the C function rpl_func may have a slightly different
134 declaration. A cast is used to silence the "invalid conversion" error
135 that would otherwise occur. */
136 #if defined __cplusplus && defined GNULIB_NAMESPACE
137 # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
138 namespace GNULIB_NAMESPACE \
140 rettype (*const func) parameters = \
141 reinterpret_cast<rettype(*)parameters>(::rpl_func); \
143 _GL_EXTERN_C int _gl_cxxalias_dummy
145 # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
146 _GL_EXTERN_C int _gl_cxxalias_dummy
149 /* _GL_CXXALIAS_SYS (func, rettype, parameters);
150 declares a C++ alias called GNULIB_NAMESPACE::func
151 that redirects to the system provided function func, if GNULIB_NAMESPACE
154 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
156 #if defined __cplusplus && defined GNULIB_NAMESPACE
157 /* If we were to write
158 rettype (*const func) parameters = ::func;
159 like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
160 better (remove an indirection through a 'static' pointer variable),
161 but then the _GL_CXXALIASWARN macro below would cause a warning not only
162 for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
163 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
164 namespace GNULIB_NAMESPACE \
166 static rettype (*func) parameters = ::func; \
168 _GL_EXTERN_C int _gl_cxxalias_dummy
170 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
171 _GL_EXTERN_C int _gl_cxxalias_dummy
174 /* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
175 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
176 except that the C function func may have a slightly different declaration.
177 A cast is used to silence the "invalid conversion" error that would
179 #if defined __cplusplus && defined GNULIB_NAMESPACE
180 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
181 namespace GNULIB_NAMESPACE \
183 static rettype (*func) parameters = \
184 reinterpret_cast<rettype(*)parameters>(::func); \
186 _GL_EXTERN_C int _gl_cxxalias_dummy
188 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
189 _GL_EXTERN_C int _gl_cxxalias_dummy
192 /* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
193 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
194 except that the C function is picked among a set of overloaded functions,
195 namely the one with rettype2 and parameters2. Two consecutive casts
196 are used to silence the "cannot find a match" and "invalid conversion"
197 errors that would otherwise occur. */
198 #if defined __cplusplus && defined GNULIB_NAMESPACE
199 /* The outer cast must be a reinterpret_cast.
200 The inner cast: When the function is defined as a set of overloaded
201 functions, it works as a static_cast<>, choosing the designated variant.
202 When the function is defined as a single variant, it works as a
203 reinterpret_cast<>. The parenthesized cast syntax works both ways. */
204 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
205 namespace GNULIB_NAMESPACE \
207 static rettype (*func) parameters = \
208 reinterpret_cast<rettype(*)parameters>( \
209 (rettype2(*)parameters2)(::func)); \
211 _GL_EXTERN_C int _gl_cxxalias_dummy
213 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
214 _GL_EXTERN_C int _gl_cxxalias_dummy
217 /* _GL_CXXALIASWARN (func);
218 causes a warning to be emitted when ::func is used but not when
219 GNULIB_NAMESPACE::func is used. func must be defined without overloaded
221 #if defined __cplusplus && defined GNULIB_NAMESPACE
222 # define _GL_CXXALIASWARN(func) \
223 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
224 # define _GL_CXXALIASWARN_1(func,namespace) \
225 _GL_CXXALIASWARN_2 (func, namespace)
226 /* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
227 we enable the warning only when not optimizing. */
229 # define _GL_CXXALIASWARN_2(func,namespace) \
230 _GL_WARN_ON_USE (func, \
231 "The symbol ::" #func " refers to the system function. " \
232 "Use " #namespace "::" #func " instead.")
233 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
234 # define _GL_CXXALIASWARN_2(func,namespace) \
235 extern __typeof__ (func) func
237 # define _GL_CXXALIASWARN_2(func,namespace) \
238 _GL_EXTERN_C int _gl_cxxalias_dummy
241 # define _GL_CXXALIASWARN(func) \
242 _GL_EXTERN_C int _gl_cxxalias_dummy
245 /* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
246 causes a warning to be emitted when the given overloaded variant of ::func
247 is used but not when GNULIB_NAMESPACE::func is used. */
248 #if defined __cplusplus && defined GNULIB_NAMESPACE
249 # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
250 _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
252 # define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
253 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
254 /* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
255 we enable the warning only when not optimizing. */
257 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
258 _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
259 "The symbol ::" #func " refers to the system function. " \
260 "Use " #namespace "::" #func " instead.")
261 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
262 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
263 extern __typeof__ (func) func
265 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
266 _GL_EXTERN_C int _gl_cxxalias_dummy
269 # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
270 _GL_EXTERN_C int _gl_cxxalias_dummy
273 #endif /* _GL_CXXDEFS_H */