aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2017-03-14 13:44:11 -0700
committerPaul Eggert2017-03-14 14:50:02 -0700
commitfac0bb9cf76072941ae9dc9c7019929eb1a0f1dd (patch)
tree1b9618b5eea568e8230b4348af3df1084bd63e67 /lib
parent5a64d78854998c2ed6d9b8de1b593d8462b8fa39 (diff)
downloademacs-fac0bb9cf76072941ae9dc9c7019929eb1a0f1dd.tar.gz
emacs-fac0bb9cf76072941ae9dc9c7019929eb1a0f1dd.zip
Merge from gnulib
This incorporates: 2017-03-14 snippets: move unadjusted snippet sources to lib 2017-03-14 gnulib-tool: fix typo in comment output 2017-03-14 snippets: work around GNU Make 3.82 VPATH 2017-03-13 gnulib-tool: minor --gnu-make fixups 2017-03-12 gnulib-tool: new option --gnu-make * .gitignore: Remove lib/arg-nonnull.h, lib/c++defs.h, lib/warn-on-use.h. Change exception from build-aux/snippet/_Noreturn.h to lib/_Noreturn.h. * admin/authors.el (authors-renamed-files-regexps): * admin/notes/copyright, make-dist: The snippet files moved from build-aux/snippet to lib. * lib/_Noreturn.h: Rename from build-aux/snippet/_Noreturn.h. * lib/arg-nonnull.h: Rename from build-aux/snippet/arg-nonnull.h. * lib/c++defs.h: Rename from build-aux/snippet/c++defs.h. * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate. * lib/warn-on-use.h: Rename from build-aux/snippet/warn-on-use.h.
Diffstat (limited to 'lib')
-rw-r--r--lib/_Noreturn.h10
-rw-r--r--lib/arg-nonnull.h26
-rw-r--r--lib/c++defs.h316
-rw-r--r--lib/gnulib.mk70
-rw-r--r--lib/warn-on-use.h109
5 files changed, 480 insertions, 51 deletions
diff --git a/lib/_Noreturn.h b/lib/_Noreturn.h
new file mode 100644
index 00000000000..c44ad89b7c0
--- /dev/null
+++ b/lib/_Noreturn.h
@@ -0,0 +1,10 @@
1#if !defined _Noreturn && __STDC_VERSION__ < 201112
2# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
3 || 0x5110 <= __SUNPRO_C)
4# define _Noreturn __attribute__ ((__noreturn__))
5# elif 1200 <= _MSC_VER
6# define _Noreturn __declspec (noreturn)
7# else
8# define _Noreturn
9# endif
10#endif
diff --git a/lib/arg-nonnull.h b/lib/arg-nonnull.h
new file mode 100644
index 00000000000..1e62cc89827
--- /dev/null
+++ b/lib/arg-nonnull.h
@@ -0,0 +1,26 @@
1/* A C macro for declaring that specific arguments must not be NULL.
2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
18 that the values passed as arguments n, ..., m must be non-NULL pointers.
19 n = 1 stands for the first argument, n = 2 for the second argument etc. */
20#ifndef _GL_ARG_NONNULL
21# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
22# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
23# else
24# define _GL_ARG_NONNULL(params)
25# endif
26#endif
diff --git a/lib/c++defs.h b/lib/c++defs.h
new file mode 100644
index 00000000000..f03f3591c35
--- /dev/null
+++ b/lib/c++defs.h
@@ -0,0 +1,316 @@
1/* C++ compatible function declaration macros.
2 Copyright (C) 2010-2017 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifndef _GL_CXXDEFS_H
18#define _GL_CXXDEFS_H
19
20/* Begin/end the GNULIB_NAMESPACE namespace. */
21#if defined __cplusplus && defined GNULIB_NAMESPACE
22# define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
23# define _GL_END_NAMESPACE }
24#else
25# define _GL_BEGIN_NAMESPACE
26# define _GL_END_NAMESPACE
27#endif
28
29/* The three most frequent use cases of these macros are:
30
31 * For providing a substitute for a function that is missing on some
32 platforms, but is declared and works fine on the platforms on which
33 it exists:
34
35 #if @GNULIB_FOO@
36 # if !@HAVE_FOO@
37 _GL_FUNCDECL_SYS (foo, ...);
38 # endif
39 _GL_CXXALIAS_SYS (foo, ...);
40 _GL_CXXALIASWARN (foo);
41 #elif defined GNULIB_POSIXCHECK
42 ...
43 #endif
44
45 * For providing a replacement for a function that exists on all platforms,
46 but is broken/insufficient and needs to be replaced on some platforms:
47
48 #if @GNULIB_FOO@
49 # if @REPLACE_FOO@
50 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
51 # undef foo
52 # define foo rpl_foo
53 # endif
54 _GL_FUNCDECL_RPL (foo, ...);
55 _GL_CXXALIAS_RPL (foo, ...);
56 # else
57 _GL_CXXALIAS_SYS (foo, ...);
58 # endif
59 _GL_CXXALIASWARN (foo);
60 #elif defined GNULIB_POSIXCHECK
61 ...
62 #endif
63
64 * For providing a replacement for a function that exists on some platforms
65 but is broken/insufficient and needs to be replaced on some of them and
66 is additionally either missing or undeclared on some other platforms:
67
68 #if @GNULIB_FOO@
69 # if @REPLACE_FOO@
70 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
71 # undef foo
72 # define foo rpl_foo
73 # endif
74 _GL_FUNCDECL_RPL (foo, ...);
75 _GL_CXXALIAS_RPL (foo, ...);
76 # else
77 # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
78 _GL_FUNCDECL_SYS (foo, ...);
79 # endif
80 _GL_CXXALIAS_SYS (foo, ...);
81 # endif
82 _GL_CXXALIASWARN (foo);
83 #elif defined GNULIB_POSIXCHECK
84 ...
85 #endif
86*/
87
88/* _GL_EXTERN_C declaration;
89 performs the declaration with C linkage. */
90#if defined __cplusplus
91# define _GL_EXTERN_C extern "C"
92#else
93# define _GL_EXTERN_C extern
94#endif
95
96/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
97 declares a replacement function, named rpl_func, with the given prototype,
98 consisting of return type, parameters, and attributes.
99 Example:
100 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
101 _GL_ARG_NONNULL ((1)));
102 */
103#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
104 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
105#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
106 _GL_EXTERN_C rettype rpl_func parameters_and_attributes
107
108/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
109 declares the system function, named func, with the given prototype,
110 consisting of return type, parameters, and attributes.
111 Example:
112 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
113 _GL_ARG_NONNULL ((1)));
114 */
115#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
116 _GL_EXTERN_C rettype func parameters_and_attributes
117
118/* _GL_CXXALIAS_RPL (func, rettype, parameters);
119 declares a C++ alias called GNULIB_NAMESPACE::func
120 that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
121 Example:
122 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
123
124 Wrapping rpl_func in an object with an inline conversion operator
125 avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
126 actually used in the program. */
127#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
128 _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
129#if defined __cplusplus && defined GNULIB_NAMESPACE
130# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
131 namespace GNULIB_NAMESPACE \
132 { \
133 static const struct _gl_ ## func ## _wrapper \
134 { \
135 typedef rettype (*type) parameters; \
136 \
137 inline operator type () const \
138 { \
139 return ::rpl_func; \
140 } \
141 } func = {}; \
142 } \
143 _GL_EXTERN_C int _gl_cxxalias_dummy
144#else
145# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
146 _GL_EXTERN_C int _gl_cxxalias_dummy
147#endif
148
149/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
150 is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
151 except that the C function rpl_func may have a slightly different
152 declaration. A cast is used to silence the "invalid conversion" error
153 that would otherwise occur. */
154#if defined __cplusplus && defined GNULIB_NAMESPACE
155# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
156 namespace GNULIB_NAMESPACE \
157 { \
158 static const struct _gl_ ## func ## _wrapper \
159 { \
160 typedef rettype (*type) parameters; \
161 \
162 inline operator type () const \
163 { \
164 return reinterpret_cast<type>(::rpl_func); \
165 } \
166 } func = {}; \
167 } \
168 _GL_EXTERN_C int _gl_cxxalias_dummy
169#else
170# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
171 _GL_EXTERN_C int _gl_cxxalias_dummy
172#endif
173
174/* _GL_CXXALIAS_SYS (func, rettype, parameters);
175 declares a C++ alias called GNULIB_NAMESPACE::func
176 that redirects to the system provided function func, if GNULIB_NAMESPACE
177 is defined.
178 Example:
179 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
180
181 Wrapping func in an object with an inline conversion operator
182 avoids a reference to func unless GNULIB_NAMESPACE::func is
183 actually used in the program. */
184#if defined __cplusplus && defined GNULIB_NAMESPACE
185# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
186 namespace GNULIB_NAMESPACE \
187 { \
188 static const struct _gl_ ## func ## _wrapper \
189 { \
190 typedef rettype (*type) parameters; \
191 \
192 inline operator type () const \
193 { \
194 return ::func; \
195 } \
196 } func = {}; \
197 } \
198 _GL_EXTERN_C int _gl_cxxalias_dummy
199#else
200# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
201 _GL_EXTERN_C int _gl_cxxalias_dummy
202#endif
203
204/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
205 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
206 except that the C function func may have a slightly different declaration.
207 A cast is used to silence the "invalid conversion" error that would
208 otherwise occur. */
209#if defined __cplusplus && defined GNULIB_NAMESPACE
210# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
211 namespace GNULIB_NAMESPACE \
212 { \
213 static const struct _gl_ ## func ## _wrapper \
214 { \
215 typedef rettype (*type) parameters; \
216 \
217 inline operator type () const \
218 { \
219 return reinterpret_cast<type>(::func); \
220 } \
221 } func = {}; \
222 } \
223 _GL_EXTERN_C int _gl_cxxalias_dummy
224#else
225# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
226 _GL_EXTERN_C int _gl_cxxalias_dummy
227#endif
228
229/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
230 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
231 except that the C function is picked among a set of overloaded functions,
232 namely the one with rettype2 and parameters2. Two consecutive casts
233 are used to silence the "cannot find a match" and "invalid conversion"
234 errors that would otherwise occur. */
235#if defined __cplusplus && defined GNULIB_NAMESPACE
236 /* The outer cast must be a reinterpret_cast.
237 The inner cast: When the function is defined as a set of overloaded
238 functions, it works as a static_cast<>, choosing the designated variant.
239 When the function is defined as a single variant, it works as a
240 reinterpret_cast<>. The parenthesized cast syntax works both ways. */
241# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
242 namespace GNULIB_NAMESPACE \
243 { \
244 static const struct _gl_ ## func ## _wrapper \
245 { \
246 typedef rettype (*type) parameters; \
247 \
248 inline operator type () const \
249 { \
250 return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); \
251 } \
252 } func = {}; \
253 } \
254 _GL_EXTERN_C int _gl_cxxalias_dummy
255#else
256# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
257 _GL_EXTERN_C int _gl_cxxalias_dummy
258#endif
259
260/* _GL_CXXALIASWARN (func);
261 causes a warning to be emitted when ::func is used but not when
262 GNULIB_NAMESPACE::func is used. func must be defined without overloaded
263 variants. */
264#if defined __cplusplus && defined GNULIB_NAMESPACE
265# define _GL_CXXALIASWARN(func) \
266 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
267# define _GL_CXXALIASWARN_1(func,namespace) \
268 _GL_CXXALIASWARN_2 (func, namespace)
269/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
270 we enable the warning only when not optimizing. */
271# if !__OPTIMIZE__
272# define _GL_CXXALIASWARN_2(func,namespace) \
273 _GL_WARN_ON_USE (func, \
274 "The symbol ::" #func " refers to the system function. " \
275 "Use " #namespace "::" #func " instead.")
276# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
277# define _GL_CXXALIASWARN_2(func,namespace) \
278 extern __typeof__ (func) func
279# else
280# define _GL_CXXALIASWARN_2(func,namespace) \
281 _GL_EXTERN_C int _gl_cxxalias_dummy
282# endif
283#else
284# define _GL_CXXALIASWARN(func) \
285 _GL_EXTERN_C int _gl_cxxalias_dummy
286#endif
287
288/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
289 causes a warning to be emitted when the given overloaded variant of ::func
290 is used but not when GNULIB_NAMESPACE::func is used. */
291#if defined __cplusplus && defined GNULIB_NAMESPACE
292# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
293 _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
294 GNULIB_NAMESPACE)
295# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
296 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
297/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
298 we enable the warning only when not optimizing. */
299# if !__OPTIMIZE__
300# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
301 _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
302 "The symbol ::" #func " refers to the system function. " \
303 "Use " #namespace "::" #func " instead.")
304# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
305# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
306 extern __typeof__ (func) func
307# else
308# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
309 _GL_EXTERN_C int _gl_cxxalias_dummy
310# endif
311#else
312# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
313 _GL_EXTERN_C int _gl_cxxalias_dummy
314#endif
315
316#endif /* _GL_CXXDEFS_H */
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index 7a0de1b440d..4109e7f6af5 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -25,6 +25,7 @@
25 25
26 26
27MOSTLYCLEANFILES += core *.stackdump 27MOSTLYCLEANFILES += core *.stackdump
28# No GNU Make output.
28 29
29noinst_LIBRARIES += libgnu.a 30noinst_LIBRARIES += libgnu.a
30 31
@@ -873,81 +874,48 @@ EXTRA_DIST += signal.in.h
873## begin gnulib module snippet/_Noreturn 874## begin gnulib module snippet/_Noreturn
874 875
875# Because this Makefile snippet defines a variable used by other 876# Because this Makefile snippet defines a variable used by other
876# gnulib Makefile snippets, it must be present in all Makefile.am that 877# gnulib Makefile snippets, it must be present in all makefiles that
877# need it. This is ensured by the applicability 'all' defined above. 878# need it. This is ensured by the applicability 'all' defined above.
878 879
879_NORETURN_H=$(top_srcdir)/build-aux/snippet/_Noreturn.h 880_NORETURN_H=$(srcdir)/_Noreturn.h
880 881
881EXTRA_DIST += $(top_srcdir)/build-aux/snippet/_Noreturn.h 882EXTRA_DIST += _Noreturn.h
882 883
883## end gnulib module snippet/_Noreturn 884## end gnulib module snippet/_Noreturn
884 885
885## begin gnulib module snippet/arg-nonnull 886## begin gnulib module snippet/arg-nonnull
886 887
887# The BUILT_SOURCES created by this Makefile snippet are not used via #include 888# Because this Makefile snippet defines a variable used by other
888# statements but through direct file reference. Therefore this snippet must be 889# gnulib Makefile snippets, it must be present in all makefiles that
889# present in all Makefile.am that need it. This is ensured by the applicability 890# need it. This is ensured by the applicability 'all' defined above.
890# 'all' defined above.
891
892BUILT_SOURCES += arg-nonnull.h
893# The arg-nonnull.h that gets inserted into generated .h files is the same as
894# build-aux/snippet/arg-nonnull.h, except that it has the copyright header cut
895# off.
896arg-nonnull.h: $(top_srcdir)/build-aux/snippet/arg-nonnull.h
897 $(AM_V_GEN)rm -f $@-t $@ && \
898 sed -n -e '/GL_ARG_NONNULL/,$$p' \
899 < $(top_srcdir)/build-aux/snippet/arg-nonnull.h \
900 > $@-t && \
901 mv $@-t $@
902MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t
903 891
904ARG_NONNULL_H=arg-nonnull.h 892ARG_NONNULL_H=$(srcdir)/arg-nonnull.h
905 893
906EXTRA_DIST += $(top_srcdir)/build-aux/snippet/arg-nonnull.h 894EXTRA_DIST += arg-nonnull.h
907 895
908## end gnulib module snippet/arg-nonnull 896## end gnulib module snippet/arg-nonnull
909 897
910## begin gnulib module snippet/c++defs 898## begin gnulib module snippet/c++defs
911 899
912# The BUILT_SOURCES created by this Makefile snippet are not used via #include 900# Because this Makefile snippet defines a variable used by other
913# statements but through direct file reference. Therefore this snippet must be 901# gnulib Makefile snippets, it must be present in all makefiles that
914# present in all Makefile.am that need it. This is ensured by the applicability 902# need it. This is ensured by the applicability 'all' defined above.
915# 'all' defined above.
916
917BUILT_SOURCES += c++defs.h
918# The c++defs.h that gets inserted into generated .h files is the same as
919# build-aux/snippet/c++defs.h, except that it has the copyright header cut off.
920c++defs.h: $(top_srcdir)/build-aux/snippet/c++defs.h
921 $(AM_V_GEN)rm -f $@-t $@ && \
922 sed -n -e '/_GL_CXXDEFS/,$$p' \
923 < $(top_srcdir)/build-aux/snippet/c++defs.h \
924 > $@-t && \
925 mv $@-t $@
926MOSTLYCLEANFILES += c++defs.h c++defs.h-t
927 903
928CXXDEFS_H=c++defs.h 904CXXDEFS_H=$(srcdir)/c++defs.h
929 905
930EXTRA_DIST += $(top_srcdir)/build-aux/snippet/c++defs.h 906EXTRA_DIST += c++defs.h
931 907
932## end gnulib module snippet/c++defs 908## end gnulib module snippet/c++defs
933 909
934## begin gnulib module snippet/warn-on-use 910## begin gnulib module snippet/warn-on-use
935 911
936BUILT_SOURCES += warn-on-use.h 912# Because this Makefile snippet defines a variable used by other
937# The warn-on-use.h that gets inserted into generated .h files is the same as 913# gnulib Makefile snippets, it must be present in all makefiles that
938# build-aux/snippet/warn-on-use.h, except that it has the copyright header cut 914# need it. This is ensured by the applicability 'all' defined above.
939# off.
940warn-on-use.h: $(top_srcdir)/build-aux/snippet/warn-on-use.h
941 $(AM_V_GEN)rm -f $@-t $@ && \
942 sed -n -e '/^.ifndef/,$$p' \
943 < $(top_srcdir)/build-aux/snippet/warn-on-use.h \
944 > $@-t && \
945 mv $@-t $@
946MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t
947 915
948WARN_ON_USE_H=warn-on-use.h 916WARN_ON_USE_H=$(srcdir)/warn-on-use.h
949 917
950EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h 918EXTRA_DIST += warn-on-use.h
951 919
952## end gnulib module snippet/warn-on-use 920## end gnulib module snippet/warn-on-use
953 921
diff --git a/lib/warn-on-use.h b/lib/warn-on-use.h
new file mode 100644
index 00000000000..3c0eb579fa2
--- /dev/null
+++ b/lib/warn-on-use.h
@@ -0,0 +1,109 @@
1/* A C macro for emitting warnings if a function is used.
2 Copyright (C) 2010-2017 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
18 for FUNCTION which will then trigger a compiler warning containing
19 the text of "literal string" anywhere that function is called, if
20 supported by the compiler. If the compiler does not support this
21 feature, the macro expands to an unused extern declaration.
22
23 This macro is useful for marking a function as a potential
24 portability trap, with the intent that "literal string" include
25 instructions on the replacement function that should be used
26 instead. However, one of the reasons that a function is a
27 portability trap is if it has the wrong signature. Declaring
28 FUNCTION with a different signature in C is a compilation error, so
29 this macro must use the same type as any existing declaration so
30 that programs that avoid the problematic FUNCTION do not fail to
31 compile merely because they included a header that poisoned the
32 function. But this implies that _GL_WARN_ON_USE is only safe to
33 use if FUNCTION is known to already have a declaration. Use of
34 this macro implies that there must not be any other macro hiding
35 the declaration of FUNCTION; but undefining FUNCTION first is part
36 of the poisoning process anyway (although for symbols that are
37 provided only via a macro, the result is a compilation error rather
38 than a warning containing "literal string"). Also note that in
39 C++, it is only safe to use if FUNCTION has no overloads.
40
41 For an example, it is possible to poison 'getline' by:
42 - adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
43 [getline]) in configure.ac, which potentially defines
44 HAVE_RAW_DECL_GETLINE
45 - adding this code to a header that wraps the system <stdio.h>:
46 #undef getline
47 #if HAVE_RAW_DECL_GETLINE
48 _GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
49 "not universally present; use the gnulib module getline");
50 #endif
51
52 It is not possible to directly poison global variables. But it is
53 possible to write a wrapper accessor function, and poison that
54 (less common usage, like &environ, will cause a compilation error
55 rather than issue the nice warning, but the end result of informing
56 the developer about their portability problem is still achieved):
57 #if HAVE_RAW_DECL_ENVIRON
58 static char ***rpl_environ (void) { return &environ; }
59 _GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
60 # undef environ
61 # define environ (*rpl_environ ())
62 #endif
63 */
64#ifndef _GL_WARN_ON_USE
65
66# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
67/* A compiler attribute is available in gcc versions 4.3.0 and later. */
68# define _GL_WARN_ON_USE(function, message) \
69extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
70# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
71/* Verify the existence of the function. */
72# define _GL_WARN_ON_USE(function, message) \
73extern __typeof__ (function) function
74# else /* Unsupported. */
75# define _GL_WARN_ON_USE(function, message) \
76_GL_WARN_EXTERN_C int _gl_warn_on_use
77# endif
78#endif
79
80/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
81 is like _GL_WARN_ON_USE (function, "string"), except that the function is
82 declared with the given prototype, consisting of return type, parameters,
83 and attributes.
84 This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
85 not work in this case. */
86#ifndef _GL_WARN_ON_USE_CXX
87# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
88# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
89extern rettype function parameters_and_attributes \
90 __attribute__ ((__warning__ (msg)))
91# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
92/* Verify the existence of the function. */
93# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
94extern rettype function parameters_and_attributes
95# else /* Unsupported. */
96# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
97_GL_WARN_EXTERN_C int _gl_warn_on_use
98# endif
99#endif
100
101/* _GL_WARN_EXTERN_C declaration;
102 performs the declaration with C linkage. */
103#ifndef _GL_WARN_EXTERN_C
104# if defined __cplusplus
105# define _GL_WARN_EXTERN_C extern "C"
106# else
107# define _GL_WARN_EXTERN_C extern
108# endif
109#endif