Blame lib/c++defs.h

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