diff options
Diffstat (limited to 'gl/c++defs.h')
| -rw-r--r-- | gl/c++defs.h | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/gl/c++defs.h b/gl/c++defs.h index eb66967b..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-2024 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,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,24 @@ | |||
| 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 (func, rettype, parameters, [attributes]); |
| 115 | declares the system function, named func, with the given prototype, | 131 | declares the system function, named func, with the given prototype, |
| 116 | consisting of return type, parameters, and attributes. | 132 | consisting of return type, parameters, and attributes. |
| 117 | Example: | 133 | Although attributes are optional, the comma before them is required |
| 118 | _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...) | 134 | for portability to C17 and earlier. The attribute _GL_ATTRIBUTE_NOTHROW, |
| 119 | _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); | ||
| 120 | */ | 140 | */ |
| 121 | #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \ | 141 | #define _GL_FUNCDECL_SYS(func,rettype,parameters,...) \ |
| 122 | _GL_EXTERN_C rettype func parameters_and_attributes | 142 | _GL_EXTERN_C_FUNC __VA_ARGS__ rettype func parameters |
| 123 | 143 | ||
| 124 | /* _GL_CXXALIAS_RPL (func, rettype, parameters); | 144 | /* _GL_CXXALIAS_RPL (func, rettype, parameters); |
| 125 | declares a C++ alias called GNULIB_NAMESPACE::func | 145 | declares a C++ alias called GNULIB_NAMESPACE::func |
| @@ -297,7 +317,7 @@ | |||
| 297 | _GL_WARN_ON_USE (func, \ | 317 | _GL_WARN_ON_USE (func, \ |
| 298 | "The symbol ::" #func " refers to the system function. " \ | 318 | "The symbol ::" #func " refers to the system function. " \ |
| 299 | "Use " #namespace "::" #func " instead.") | 319 | "Use " #namespace "::" #func " instead.") |
| 300 | # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING | 320 | # elif (__GNUC__ >= 3 || defined __clang__) && GNULIB_STRICT_CHECKING |
| 301 | # define _GL_CXXALIASWARN_2(func,namespace) \ | 321 | # define _GL_CXXALIASWARN_2(func,namespace) \ |
| 302 | extern __typeof__ (func) func | 322 | extern __typeof__ (func) func |
| 303 | # else | 323 | # else |
