summaryrefslogtreecommitdiffstats
path: root/gl/c++defs.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/c++defs.h')
-rw-r--r--gl/c++defs.h64
1 files changed, 47 insertions, 17 deletions
diff --git a/gl/c++defs.h b/gl/c++defs.h
index eb66967b..cfe68cb1 100644
--- a/gl/c++defs.h
+++ b/gl/c++defs.h
@@ -1,5 +1,5 @@
1/* C++ compatible function declaration macros. 1/* C++ compatible function declaration macros.
2 Copyright (C) 2010-2024 Free Software Foundation, Inc. 2 Copyright (C) 2010-2026 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify it 4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published 5 under the terms of the GNU Lesser General Public License as published
@@ -93,11 +93,27 @@
93# define _GL_EXTERN_C extern 93# define _GL_EXTERN_C extern
94#endif 94#endif
95 95
96/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes); 96/* _GL_EXTERN_C_FUNC declaration;
97 performs the declaration of a function with C linkage. */
98#if defined __cplusplus
99# define _GL_EXTERN_C_FUNC extern "C"
100#else
101/* In C mode, omit the 'extern' keyword, because attributes in bracket syntax
102 are not allowed between 'extern' and the return type (see gnulib-common.m4).
103 */
104# define _GL_EXTERN_C_FUNC
105#endif
106
107/* _GL_FUNCDECL_RPL (func, rettype, parameters, [attributes]);
97 declares a replacement function, named rpl_func, with the given prototype, 108 declares a replacement function, named rpl_func, with the given prototype,
98 consisting of return type, parameters, and attributes. 109 consisting of return type, parameters, and attributes.
99 Example: 110 Although attributes are optional, the comma before them is required
100 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...) 111 for portability to C17 and earlier. The attribute _GL_ATTRIBUTE_NOTHROW,
112 if needed, must be placed after the _GL_FUNCDECL_RPL invocation,
113 at the end of the declaration.
114 Examples:
115 _GL_FUNCDECL_RPL (free, void, (void *ptr), ) _GL_ATTRIBUTE_NOTHROW;
116 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...),
101 _GL_ARG_NONNULL ((1))); 117 _GL_ARG_NONNULL ((1)));
102 118
103 Note: Attributes, such as _GL_ATTRIBUTE_DEPRECATED, are supported in front 119 Note: Attributes, such as _GL_ATTRIBUTE_DEPRECATED, are supported in front
@@ -106,20 +122,34 @@
106 [[...]] extern "C" <declaration>; 122 [[...]] extern "C" <declaration>;
107 is invalid syntax in C++.) 123 is invalid syntax in C++.)
108 */ 124 */
109#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \ 125#define _GL_FUNCDECL_RPL(func,rettype,parameters,...) \
110 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes) 126 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters, __VA_ARGS__)
111#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \ 127#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters,...) \
112 _GL_EXTERN_C rettype rpl_func parameters_and_attributes 128 _GL_EXTERN_C_FUNC __VA_ARGS__ rettype rpl_func parameters
113 129
114/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes); 130/* _GL_FUNCDECL_SYS_NAME (func) expands to plain func if C++, and to
131 parenthesized func otherwise. Parenthesization is needed in C23 if
132 the function is like strchr and so is a qualifier-generic macro
133 that expands to something more complicated. */
134#ifdef __cplusplus
135# define _GL_FUNCDECL_SYS_NAME(func) func
136#else
137# define _GL_FUNCDECL_SYS_NAME(func) (func)
138#endif
139
140/* _GL_FUNCDECL_SYS (func, rettype, parameters, [attributes]);
115 declares the system function, named func, with the given prototype, 141 declares the system function, named func, with the given prototype,
116 consisting of return type, parameters, and attributes. 142 consisting of return type, parameters, and attributes.
117 Example: 143 Although attributes are optional, the comma before them is required
118 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...) 144 for portability to C17 and earlier. The attribute _GL_ATTRIBUTE_NOTHROW,
119 _GL_ARG_NONNULL ((1))); 145 if needed, must be placed after the _GL_FUNCDECL_RPL invocation,
146 at the end of the declaration.
147 Examples:
148 _GL_FUNCDECL_SYS (getumask, mode_t, (void), ) _GL_ATTRIBUTE_NOTHROW;
149 _GL_FUNCDECL_SYS (posix_openpt, int, (int flags), _GL_ATTRIBUTE_NODISCARD);
120 */ 150 */
121#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \ 151#define _GL_FUNCDECL_SYS(func,rettype,parameters,...) \
122 _GL_EXTERN_C rettype func parameters_and_attributes 152 _GL_EXTERN_C_FUNC __VA_ARGS__ rettype _GL_FUNCDECL_SYS_NAME (func) parameters
123 153
124/* _GL_CXXALIAS_RPL (func, rettype, parameters); 154/* _GL_CXXALIAS_RPL (func, rettype, parameters);
125 declares a C++ alias called GNULIB_NAMESPACE::func 155 declares a C++ alias called GNULIB_NAMESPACE::func
@@ -290,14 +320,14 @@
290 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE) 320 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
291# define _GL_CXXALIASWARN_1(func,namespace) \ 321# define _GL_CXXALIASWARN_1(func,namespace) \
292 _GL_CXXALIASWARN_2 (func, namespace) 322 _GL_CXXALIASWARN_2 (func, namespace)
293/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>, 323/* To work around GCC bug <https://gcc.gnu.org/PR43881>,
294 we enable the warning only when not optimizing. */ 324 we enable the warning only when not optimizing. */
295# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__) 325# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
296# define _GL_CXXALIASWARN_2(func,namespace) \ 326# define _GL_CXXALIASWARN_2(func,namespace) \
297 _GL_WARN_ON_USE (func, \ 327 _GL_WARN_ON_USE (func, \
298 "The symbol ::" #func " refers to the system function. " \ 328 "The symbol ::" #func " refers to the system function. " \
299 "Use " #namespace "::" #func " instead.") 329 "Use " #namespace "::" #func " instead.")
300# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING 330# elif (__GNUC__ >= 3 || defined __clang__) && GNULIB_STRICT_CHECKING
301# define _GL_CXXALIASWARN_2(func,namespace) \ 331# define _GL_CXXALIASWARN_2(func,namespace) \
302 extern __typeof__ (func) func 332 extern __typeof__ (func) func
303# else 333# else
@@ -318,7 +348,7 @@
318 GNULIB_NAMESPACE) 348 GNULIB_NAMESPACE)
319# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \ 349# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
320 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace) 350 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
321/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>, 351/* To work around GCC bug <https://gcc.gnu.org/PR43881>,
322 we enable the warning only when not optimizing. */ 352 we enable the warning only when not optimizing. */
323# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__) 353# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
324# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ 354# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \