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.h56
1 files changed, 41 insertions, 15 deletions
diff --git a/gl/c++defs.h b/gl/c++defs.h
index 8ad46951..df98a5ae 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-2023 Free Software Foundation, Inc. 2 Copyright (C) 2010-2025 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,27 +93,53 @@
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)));
118
119 Note: Attributes, such as _GL_ATTRIBUTE_DEPRECATED, are supported in front
120 of a _GL_FUNCDECL_RPL invocation only in C mode, not in C++ mode. (That's
121 because
122 [[...]] extern "C" <declaration>;
123 is invalid syntax in C++.)
102 */ 124 */
103#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \ 125#define _GL_FUNCDECL_RPL(func,rettype,parameters,...) \
104 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes) 126 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters, __VA_ARGS__)
105#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \ 127#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters,...) \
106 _GL_EXTERN_C rettype rpl_func parameters_and_attributes 128 _GL_EXTERN_C_FUNC __VA_ARGS__ rettype rpl_func parameters
107 129
108/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes); 130/* _GL_FUNCDECL_SYS (func, rettype, parameters, [attributes]);
109 declares the system function, named func, with the given prototype, 131 declares the system function, named func, with the given prototype,
110 consisting of return type, parameters, and attributes. 132 consisting of return type, parameters, and attributes.
111 Example: 133 Although attributes are optional, the comma before them is required
112 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...) 134 for portability to C17 and earlier. The attribute _GL_ATTRIBUTE_NOTHROW,
113 _GL_ARG_NONNULL ((1))); 135 if needed, must be placed after the _GL_FUNCDECL_RPL invocation,
136 at the end of the declaration.
137 Examples:
138 _GL_FUNCDECL_SYS (getumask, mode_t, (void), ) _GL_ATTRIBUTE_NOTHROW;
139 _GL_FUNCDECL_SYS (posix_openpt, int, (int flags), _GL_ATTRIBUTE_NODISCARD);
114 */ 140 */
115#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \ 141#define _GL_FUNCDECL_SYS(func,rettype,parameters,...) \
116 _GL_EXTERN_C rettype func parameters_and_attributes 142 _GL_EXTERN_C_FUNC __VA_ARGS__ rettype func parameters
117 143
118/* _GL_CXXALIAS_RPL (func, rettype, parameters); 144/* _GL_CXXALIAS_RPL (func, rettype, parameters);
119 declares a C++ alias called GNULIB_NAMESPACE::func 145 declares a C++ alias called GNULIB_NAMESPACE::func
@@ -291,7 +317,7 @@
291 _GL_WARN_ON_USE (func, \ 317 _GL_WARN_ON_USE (func, \
292 "The symbol ::" #func " refers to the system function. " \ 318 "The symbol ::" #func " refers to the system function. " \
293 "Use " #namespace "::" #func " instead.") 319 "Use " #namespace "::" #func " instead.")
294# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING 320# elif (__GNUC__ >= 3 || defined __clang__) && GNULIB_STRICT_CHECKING
295# define _GL_CXXALIASWARN_2(func,namespace) \ 321# define _GL_CXXALIASWARN_2(func,namespace) \
296 extern __typeof__ (func) func 322 extern __typeof__ (func) func
297# else 323# else