From: Bruno Haible Date: Sun, 4 Jun 2023 17:27:48 +0000 (+0200) Subject: error: Fix support for library namespacing (regression 2023-05-27). X-Git-Tag: v1.0~1252 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=4b11de31a3b3e81b9c3a0b12c9f2924aefa1d84e;p=gnulib.git error: Fix support for library namespacing (regression 2023-05-27). * lib/error.in.h (error): If error is defined as a macro, define a static inline function _gl_inline_error that invokes it, and let the new error macro invoke that function. (error_at_line): If error_at_line is defined as a macro, define a static inline function _gl_inline_error_at_line that invokes it, and let the new error_at_line macro invoke that function. --- diff --git a/ChangeLog b/ChangeLog index af117a905a..eea4e17251 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2023-06-04 Bruno Haible + + error: Fix support for library namespacing (regression 2023-05-27). + * lib/error.in.h (error): If error is defined as a macro, define a + static inline function _gl_inline_error that invokes it, and let the + new error macro invoke that function. + (error_at_line): If error_at_line is defined as a macro, define a static + inline function _gl_inline_error_at_line that invokes it, and let the + new error_at_line macro invoke that function. + 2023-06-04 Bruno Haible terminfo, termcap: Fix "discards 'const' qualifier" warnings. diff --git a/lib/error.in.h b/lib/error.in.h index ef4b3c3815..94477fde08 100644 --- a/lib/error.in.h +++ b/lib/error.in.h @@ -30,7 +30,8 @@ #ifndef _@GUARD_PREFIX@_ERROR_H #define _@GUARD_PREFIX@_ERROR_H -/* This file uses _GL_ATTRIBUTE_FORMAT. */ +/* This file uses _GL_ATTRIBUTE_ALWAYS_INLINE, _GL_ATTRIBUTE_FORMAT, + _GL_ATTRIBUTE_MAYBE_UNUSED. */ #if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif @@ -108,8 +109,28 @@ _GL_FUNCDECL_SYS (error, void, _GL_CXXALIAS_SYS (error, void, (int __status, int __errnum, const char *__format, ...)); # ifndef _GL_NO_INLINE_ERROR -# define error(status, ...) \ - __gl_error_call (error, status, __VA_ARGS__) +# ifdef error +/* Only gcc ≥ 4.7 has __builtin_va_arg_pack. */ +# if _GL_GNUC_PREREQ (4, 7) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +_GL_ATTRIBUTE_MAYBE_UNUSED +static void +_GL_ATTRIBUTE_ALWAYS_INLINE +_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4)) +_gl_inline_error (int __status, int __errnum, const char *__format, ...) +{ + return error (__status, __errnum, __format, __builtin_va_arg_pack ()); +} +# pragma GCC diagnostic pop +# undef error +# define error(status, ...) \ + __gl_error_call (_gl_inline_error, status, __VA_ARGS__) +# endif +# else +# define error(status, ...) \ + __gl_error_call (error, status, __VA_ARGS__) +# endif # endif #endif #if __GLIBC__ >= 2 @@ -146,8 +167,30 @@ _GL_CXXALIAS_SYS (error_at_line, void, (int __status, int __errnum, const char *__filename, unsigned int __lineno, const char *__format, ...)); # ifndef _GL_NO_INLINE_ERROR -# define error_at_line(status, ...) \ - __gl_error_call (error_at_line, status, __VA_ARGS__) +# ifdef error_at_line +/* Only gcc ≥ 4.7 has __builtin_va_arg_pack. */ +# if _GL_GNUC_PREREQ (4, 7) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +_GL_ATTRIBUTE_MAYBE_UNUSED +static void +_GL_ATTRIBUTE_ALWAYS_INLINE +_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 5, 6)) +_gl_inline_error_at_line (int __status, int __errnum, const char *__filename, + unsigned int __lineno, const char *__format, ...) +{ + return error_at_line (__status, __errnum, __filename, __lineno, __format, + __builtin_va_arg_pack ()); +} +# pragma GCC diagnostic pop +# undef error_at_line +# define error_at_line(status, ...) \ + __gl_error_call (_gl_inline_error_at_line, status, __VA_ARGS__) +# endif +# else +# define error_at_line(status, ...) \ + __gl_error_call (error_at_line, status, __VA_ARGS__) +# endif # endif #endif _GL_CXXALIASWARN (error_at_line);