Blame build-aux/snippet/c++defs.h

Packit c06654
/* C++ compatible function declaration macros.
Packit c06654
   Copyright (C) 2010-2013 Free Software Foundation, Inc.
Packit c06654
Packit c06654
   This program is free software: you can redistribute it and/or modify it
Packit c06654
   under the terms of the GNU General Public License as published
Packit c06654
   by the Free Software Foundation; either version 3 of the License, or
Packit c06654
   (at your option) any later version.
Packit c06654
Packit c06654
   This program is distributed in the hope that it will be useful,
Packit c06654
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit c06654
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit c06654
   General Public License for more details.
Packit c06654
Packit c06654
   You should have received a copy of the GNU General Public License
Packit c06654
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit c06654
Packit c06654
#ifndef _GL_CXXDEFS_H
Packit c06654
#define _GL_CXXDEFS_H
Packit c06654
Packit c06654
/* The three most frequent use cases of these macros are:
Packit c06654
Packit c06654
   * For providing a substitute for a function that is missing on some
Packit c06654
     platforms, but is declared and works fine on the platforms on which
Packit c06654
     it exists:
Packit c06654
Packit c06654
       #if @GNULIB_FOO@
Packit c06654
       # if !@HAVE_FOO@
Packit c06654
       _GL_FUNCDECL_SYS (foo, ...);
Packit c06654
       # endif
Packit c06654
       _GL_CXXALIAS_SYS (foo, ...);
Packit c06654
       _GL_CXXALIASWARN (foo);
Packit c06654
       #elif defined GNULIB_POSIXCHECK
Packit c06654
       ...
Packit c06654
       #endif
Packit c06654
Packit c06654
   * For providing a replacement for a function that exists on all platforms,
Packit c06654
     but is broken/insufficient and needs to be replaced on some platforms:
Packit c06654
Packit c06654
       #if @GNULIB_FOO@
Packit c06654
       # if @REPLACE_FOO@
Packit c06654
       #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit c06654
       #   undef foo
Packit c06654
       #   define foo rpl_foo
Packit c06654
       #  endif
Packit c06654
       _GL_FUNCDECL_RPL (foo, ...);
Packit c06654
       _GL_CXXALIAS_RPL (foo, ...);
Packit c06654
       # else
Packit c06654
       _GL_CXXALIAS_SYS (foo, ...);
Packit c06654
       # endif
Packit c06654
       _GL_CXXALIASWARN (foo);
Packit c06654
       #elif defined GNULIB_POSIXCHECK
Packit c06654
       ...
Packit c06654
       #endif
Packit c06654
Packit c06654
   * For providing a replacement for a function that exists on some platforms
Packit c06654
     but is broken/insufficient and needs to be replaced on some of them and
Packit c06654
     is additionally either missing or undeclared on some other platforms:
Packit c06654
Packit c06654
       #if @GNULIB_FOO@
Packit c06654
       # if @REPLACE_FOO@
Packit c06654
       #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit c06654
       #   undef foo
Packit c06654
       #   define foo rpl_foo
Packit c06654
       #  endif
Packit c06654
       _GL_FUNCDECL_RPL (foo, ...);
Packit c06654
       _GL_CXXALIAS_RPL (foo, ...);
Packit c06654
       # else
Packit c06654
       #  if !@HAVE_FOO@   or   if !@HAVE_DECL_FOO@
Packit c06654
       _GL_FUNCDECL_SYS (foo, ...);
Packit c06654
       #  endif
Packit c06654
       _GL_CXXALIAS_SYS (foo, ...);
Packit c06654
       # endif
Packit c06654
       _GL_CXXALIASWARN (foo);
Packit c06654
       #elif defined GNULIB_POSIXCHECK
Packit c06654
       ...
Packit c06654
       #endif
Packit c06654
*/
Packit c06654
Packit c06654
/* _GL_EXTERN_C declaration;
Packit c06654
   performs the declaration with C linkage.  */
Packit c06654
#if defined __cplusplus
Packit c06654
# define _GL_EXTERN_C extern "C"
Packit c06654
#else
Packit c06654
# define _GL_EXTERN_C extern
Packit c06654
#endif
Packit c06654
Packit c06654
/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
Packit c06654
   declares a replacement function, named rpl_func, with the given prototype,
Packit c06654
   consisting of return type, parameters, and attributes.
Packit c06654
   Example:
Packit c06654
     _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
Packit c06654
                                  _GL_ARG_NONNULL ((1)));
Packit c06654
 */
Packit c06654
#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
Packit c06654
  _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
Packit c06654
#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
Packit c06654
  _GL_EXTERN_C rettype rpl_func parameters_and_attributes
Packit c06654
Packit c06654
/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
Packit c06654
   declares the system function, named func, with the given prototype,
Packit c06654
   consisting of return type, parameters, and attributes.
Packit c06654
   Example:
Packit c06654
     _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
Packit c06654
                                  _GL_ARG_NONNULL ((1)));
Packit c06654
 */
Packit c06654
#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
Packit c06654
  _GL_EXTERN_C rettype func parameters_and_attributes
Packit c06654
Packit c06654
/* _GL_CXXALIAS_RPL (func, rettype, parameters);
Packit c06654
   declares a C++ alias called GNULIB_NAMESPACE::func
Packit c06654
   that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
Packit c06654
   Example:
Packit c06654
     _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
Packit c06654
 */
Packit c06654
#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
Packit c06654
  _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
Packit c06654
#if defined __cplusplus && defined GNULIB_NAMESPACE
Packit c06654
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
Packit c06654
    namespace GNULIB_NAMESPACE                                \
Packit c06654
    {                                                         \
Packit c06654
      rettype (*const func) parameters = ::rpl_func;          \
Packit c06654
    }                                                         \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#else
Packit c06654
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#endif
Packit c06654
Packit c06654
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
Packit c06654
   is like  _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
Packit c06654
   except that the C function rpl_func may have a slightly different
Packit c06654
   declaration.  A cast is used to silence the "invalid conversion" error
Packit c06654
   that would otherwise occur.  */
Packit c06654
#if defined __cplusplus && defined GNULIB_NAMESPACE
Packit c06654
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
Packit c06654
    namespace GNULIB_NAMESPACE                                     \
Packit c06654
    {                                                              \
Packit c06654
      rettype (*const func) parameters =                           \
Packit c06654
        reinterpret_cast<rettype(*)parameters>(::rpl_func);        \
Packit c06654
    }                                                              \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#else
Packit c06654
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#endif
Packit c06654
Packit c06654
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
Packit c06654
   declares a C++ alias called GNULIB_NAMESPACE::func
Packit c06654
   that redirects to the system provided function func, if GNULIB_NAMESPACE
Packit c06654
   is defined.
Packit c06654
   Example:
Packit c06654
     _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
Packit c06654
 */
Packit c06654
#if defined __cplusplus && defined GNULIB_NAMESPACE
Packit c06654
  /* If we were to write
Packit c06654
       rettype (*const func) parameters = ::func;
Packit c06654
     like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
Packit c06654
     better (remove an indirection through a 'static' pointer variable),
Packit c06654
     but then the _GL_CXXALIASWARN macro below would cause a warning not only
Packit c06654
     for uses of ::func but also for uses of GNULIB_NAMESPACE::func.  */
Packit c06654
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
Packit c06654
    namespace GNULIB_NAMESPACE                     \
Packit c06654
    {                                              \
Packit c06654
      static rettype (*func) parameters = ::func;  \
Packit c06654
    }                                              \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#else
Packit c06654
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#endif
Packit c06654
Packit c06654
/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
Packit c06654
   is like  _GL_CXXALIAS_SYS (func, rettype, parameters);
Packit c06654
   except that the C function func may have a slightly different declaration.
Packit c06654
   A cast is used to silence the "invalid conversion" error that would
Packit c06654
   otherwise occur.  */
Packit c06654
#if defined __cplusplus && defined GNULIB_NAMESPACE
Packit c06654
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
Packit c06654
    namespace GNULIB_NAMESPACE                          \
Packit c06654
    {                                                   \
Packit c06654
      static rettype (*func) parameters =               \
Packit c06654
        reinterpret_cast<rettype(*)parameters>(::func); \
Packit c06654
    }                                                   \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#else
Packit c06654
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#endif
Packit c06654
Packit c06654
/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
Packit c06654
   is like  _GL_CXXALIAS_SYS (func, rettype, parameters);
Packit c06654
   except that the C function is picked among a set of overloaded functions,
Packit c06654
   namely the one with rettype2 and parameters2.  Two consecutive casts
Packit c06654
   are used to silence the "cannot find a match" and "invalid conversion"
Packit c06654
   errors that would otherwise occur.  */
Packit c06654
#if defined __cplusplus && defined GNULIB_NAMESPACE
Packit c06654
  /* The outer cast must be a reinterpret_cast.
Packit c06654
     The inner cast: When the function is defined as a set of overloaded
Packit c06654
     functions, it works as a static_cast<>, choosing the designated variant.
Packit c06654
     When the function is defined as a single variant, it works as a
Packit c06654
     reinterpret_cast<>. The parenthesized cast syntax works both ways.  */
Packit c06654
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
Packit c06654
    namespace GNULIB_NAMESPACE                                                \
Packit c06654
    {                                                                         \
Packit c06654
      static rettype (*func) parameters =                                     \
Packit c06654
        reinterpret_cast<rettype(*)parameters>(                               \
Packit c06654
          (rettype2(*)parameters2)(::func));                                  \
Packit c06654
    }                                                                         \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#else
Packit c06654
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#endif
Packit c06654
Packit c06654
/* _GL_CXXALIASWARN (func);
Packit c06654
   causes a warning to be emitted when ::func is used but not when
Packit c06654
   GNULIB_NAMESPACE::func is used.  func must be defined without overloaded
Packit c06654
   variants.  */
Packit c06654
#if defined __cplusplus && defined GNULIB_NAMESPACE
Packit c06654
# define _GL_CXXALIASWARN(func) \
Packit c06654
   _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
Packit c06654
# define _GL_CXXALIASWARN_1(func,namespace) \
Packit c06654
   _GL_CXXALIASWARN_2 (func, namespace)
Packit c06654
/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
Packit c06654
   we enable the warning only when not optimizing.  */
Packit c06654
# if !__OPTIMIZE__
Packit c06654
#  define _GL_CXXALIASWARN_2(func,namespace) \
Packit c06654
    _GL_WARN_ON_USE (func, \
Packit c06654
                     "The symbol ::" #func " refers to the system function. " \
Packit c06654
                     "Use " #namespace "::" #func " instead.")
Packit c06654
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
Packit c06654
#  define _GL_CXXALIASWARN_2(func,namespace) \
Packit c06654
     extern __typeof__ (func) func
Packit c06654
# else
Packit c06654
#  define _GL_CXXALIASWARN_2(func,namespace) \
Packit c06654
     _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
# endif
Packit c06654
#else
Packit c06654
# define _GL_CXXALIASWARN(func) \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#endif
Packit c06654
Packit c06654
/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
Packit c06654
   causes a warning to be emitted when the given overloaded variant of ::func
Packit c06654
   is used but not when GNULIB_NAMESPACE::func is used.  */
Packit c06654
#if defined __cplusplus && defined GNULIB_NAMESPACE
Packit c06654
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
Packit c06654
   _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
Packit c06654
                        GNULIB_NAMESPACE)
Packit c06654
# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
Packit c06654
   _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
Packit c06654
/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
Packit c06654
   we enable the warning only when not optimizing.  */
Packit c06654
# if !__OPTIMIZE__
Packit c06654
#  define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
Packit c06654
    _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
Packit c06654
                         "The symbol ::" #func " refers to the system function. " \
Packit c06654
                         "Use " #namespace "::" #func " instead.")
Packit c06654
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
Packit c06654
#  define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
Packit c06654
     extern __typeof__ (func) func
Packit c06654
# else
Packit c06654
#  define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
Packit c06654
     _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
# endif
Packit c06654
#else
Packit c06654
# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
Packit c06654
    _GL_EXTERN_C int _gl_cxxalias_dummy
Packit c06654
#endif
Packit c06654
Packit c06654
#endif /* _GL_CXXDEFS_H */