]> git.cworth.org Git - tar/blob - build-aux/warn-on-use.h
upstream: Fix extraction of device nodes.
[tar] / build-aux / warn-on-use.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* A C macro for emitting warnings if a function is used.
4    Copyright (C) 2010 Free Software Foundation, Inc.
5
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.
10
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    Lesser General Public License for more details.
15
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/>.  */
18
19 /* _GL_WARN_ON_USE (function, "literal string") issues a declaration
20    for FUNCTION which will then trigger a compiler warning containing
21    the text of "literal string" anywhere that function is called, if
22    supported by the compiler.  If the compiler does not support this
23    feature, the macro expands to an unused extern declaration.
24
25    This macro is useful for marking a function as a potential
26    portability trap, with the intent that "literal string" include
27    instructions on the replacement function that should be used
28    instead.  However, one of the reasons that a function is a
29    portability trap is if it has the wrong signature.  Declaring
30    FUNCTION with a different signature in C is a compilation error, so
31    this macro must use the same type as any existing declaration so
32    that programs that avoid the problematic FUNCTION do not fail to
33    compile merely because they included a header that poisoned the
34    function.  But this implies that _GL_WARN_ON_USE is only safe to
35    use if FUNCTION is known to already have a declaration.  Use of
36    this macro implies that there must not be any other macro hiding
37    the declaration of FUNCTION; but undefining FUNCTION first is part
38    of the poisoning process anyway (although for symbols that are
39    provided only via a macro, the result is a compilation error rather
40    than a warning containing "literal string").  Also note that in
41    C++, it is only safe to use if FUNCTION has no overloads.
42
43    For an example, it is possible to poison 'getline' by:
44    - adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
45      [getline]) in configure.ac, which potentially defines
46      HAVE_RAW_DECL_GETLINE
47    - adding this code to a header that wraps the system <stdio.h>:
48      #undef getline
49      #if HAVE_RAW_DECL_GETLINE
50      _GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
51        "not universally present; use the gnulib module getline");
52      #endif
53
54    It is not possible to directly poison global variables.  But it is
55    possible to write a wrapper accessor function, and poison that
56    (less common usage, like &environ, will cause a compilation error
57    rather than issue the nice warning, but the end result of informing
58    the developer about their portability problem is still achieved):
59    #if HAVE_RAW_DECL_ENVIRON
60    static inline char ***rpl_environ (void) { return &environ; }
61    _GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
62    # undef environ
63    # define environ (*rpl_environ ())
64    #endif
65    */
66 #ifndef _GL_WARN_ON_USE
67
68 # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
69 /* A compiler attribute is available in gcc versions 4.3.0 and later.  */
70 #  define _GL_WARN_ON_USE(function, message) \
71 extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
72 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
73 /* Verify the existence of the function.  */
74 #  define _GL_WARN_ON_USE(function, message) \
75 extern __typeof__ (function) function
76 # else /* Unsupported.  */
77 #  define _GL_WARN_ON_USE(function, message) \
78 _GL_WARN_EXTERN_C int _gl_warn_on_use
79 # endif
80 #endif
81
82 /* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
83    is like _GL_WARN_ON_USE (function, "string"), except that the function is
84    declared with the given prototype, consisting of return type, parameters,
85    and attributes.
86    This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
87    not work in this case.  */
88 #ifndef _GL_WARN_ON_USE_CXX
89 # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
90 #  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
91 extern rettype function parameters_and_attributes \
92      __attribute__ ((__warning__ (msg)))
93 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
94 /* Verify the existence of the function.  */
95 #  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
96 extern rettype function parameters_and_attributes
97 # else /* Unsupported.  */
98 #  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
99 _GL_WARN_EXTERN_C int _gl_warn_on_use
100 # endif
101 #endif
102
103 /* _GL_WARN_EXTERN_C declaration;
104    performs the declaration with C linkage.  */
105 #ifndef _GL_WARN_EXTERN_C
106 # if defined __cplusplus
107 #  define _GL_WARN_EXTERN_C extern "C"
108 # else
109 #  define _GL_WARN_EXTERN_C extern
110 # endif
111 #endif