Hi Collin,

> I noticed similar warnings caused by the return type when building gzip
> from master (gzip is not localized). On a Fedora 42 system with
> GNULIB_SRCDIR set so the latest Gnulib commit is used instead of
> creating a git submodule:
> ...
>     $ gcc --version | sed 1q
>     gcc (GCC) 15.1.1 20250521 (Red Hat 15.1.1-2)
> ...
>     In file included from xalloc-die.c:28:
>     gettext.h:74:1: warning: mismatch in return type of built-in function 
> 'gettext'; expected 'char *' [-Wbuiltin-declaration-mismatch]
>        74 | gettext (const char *msgid)
>           | ^~~~~~~
>     gettext.h:83:1: warning: mismatch in return type of built-in function 
> 'dgettext'; expected 'char *' [-Wbuiltin-declaration-mismatch]
>        83 | dgettext (const char *domain, const char *msgid)
>           | ^~~~~~~~
>     gettext.h:93:1: warning: mismatch in return type of built-in function 
> 'dcgettext'; expected 'char *' [-Wbuiltin-declaration-mismatch]
>        93 | dcgettext (const char *domain, const char *msgid, int category)
>           | ^~~~~~~~~
>     mv -f .deps/libgzip_a-xalloc-die.Tpo .deps/libgzip_a-xalloc-die.Po
>     [...]

Thanks for the report. The relevant gcc option here is '-Wextra'.
Fixed through the patch below.

> I think I remember you mentioning that gettext will be standardized to
> return 'const char *' in the future. If so, I expect glibc and others to
> change this in the future.

I hope this will happen, in the long run. Can't guarantee it. But where I can
I want to see warnings for confusion-introducing code like

  char *s = gettext ("foo");


2025-06-01  Bruno Haible  <br...@clisp.org>

        gettext-h: Avoid warnings from "gcc -Wextra".
        Reported by Collin Funk in
        <https://lists.gnu.org/archive/html/bug-gnulib/2025-05/msg00280.html>.
        * lib/gettext.h (gettext, dgettext, dcgettext): Silence
        -Wbuiltin-declaration-mismatch warning.

diff --git a/lib/gettext.h b/lib/gettext.h
index 7a7f02e3ee..fd6c62b7eb 100644
--- a/lib/gettext.h
+++ b/lib/gettext.h
@@ -66,6 +66,10 @@
    that don't occur with enabled NLS.  */
 /* The return type 'const char *' serves the purpose of producing warnings
    for invalid uses of the value returned from these functions.  */
+#  if __GNUC__ >= 9
+#   pragma GCC diagnostic push
+#   pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
+#  endif
 __attribute__ ((__always_inline__, __gnu_inline__)) extern inline
 #  if !defined(__sun)
 const
@@ -96,6 +100,9 @@ dcgettext (const char *domain, const char *msgid, int 
category)
   (void) category;
   return msgid;
 }
+#  if __GNUC__ >= 9
+#   pragma GCC diagnostic pop
+#  endif
 # else
 /* The casts to 'const char *' serve the purpose of producing warnings
    for invalid uses of the value returned from these functions.  */




Reply via email to