On 2026-08-25 12:08, Bruno Haible wrote:
I disagree with this one. Many packages invoke 'textdomain (PACKAGE)'
unconditionally; therefore the unit test ought to do the same thing.
If !ENABLE_NLS, this is supposed to expand to a no-op.

Thanks, good point. Looks like my recent change to lib/gettext.h is at fault: 
it sometimes doesn't define textdomain. I installed the attached to fix this, 
and to document the need to define textdomain.
From a9fa6005211d9d8a9ac7afaf4c45760ea186b032 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Tue, 25 Aug 2026 13:26:06 -0700
Subject: [PATCH] gettext-h: always define textdomain

Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2026-08/msg00288.html
* lib/gettext.h (textdomain, bindtextdomain, bind_textdomain_codeset)
[!ENABLE_NLS && __GNUC__ && !__clang__ && !__cplusplus]:
Define to no-ops in this case too.
Move the definition of _LIBGETTEXT_FUNCAST up one level of
ifdeffery so that it is defined for this case.
* tests/test-gettext-h.c (main) [!ENABLE_NLS]: Call textdomain,
reverting the previous change to this file.
---
 ChangeLog                                     | 11 +++++
 .../bind_textdomain_codeset.texi              |  4 ++
 doc/posix-functions/bindtextdomain.texi       |  4 ++
 doc/posix-functions/textdomain.texi           |  4 ++
 lib/gettext.h                                 | 40 +++++++++----------
 tests/test-gettext-h.c                        |  2 -
 6 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2fbe7488ec..2eb0f5f952 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2026-08-25  Paul Eggert  <[email protected]>
 
+	gettext-h: always define textdomain
+	Problem reported by Bruno Haible in:
+	https://lists.gnu.org/r/bug-gnulib/2026-08/msg00288.html
+	* lib/gettext.h (textdomain, bindtextdomain, bind_textdomain_codeset)
+	[!ENABLE_NLS && __GNUC__ && !__clang__ && !__cplusplus]:
+	Define to no-ops in this case too.
+	Move the definition of _LIBGETTEXT_FUNCAST up one level of
+	ifdeffery so that it is defined for this case.
+	* tests/test-gettext-h.c (main) [!ENABLE_NLS]: Call textdomain,
+	reverting the previous change to this file.
+
 	getaddrinfo: getaddrinfo.c doesn’t need gettext.h
 	* lib/getaddrinfo.c: Don’t include gettext.h.
 	(_, N_): Remove; unused.
diff --git a/doc/posix-functions/bind_textdomain_codeset.texi b/doc/posix-functions/bind_textdomain_codeset.texi
index b9dba7e76b..4d92622b67 100644
--- a/doc/posix-functions/bind_textdomain_codeset.texi
+++ b/doc/posix-functions/bind_textdomain_codeset.texi
@@ -28,4 +28,8 @@ Portability problems not fixed by Gnulib:
 @item
 This function is missing on some platforms:
 macOS 14, FreeBSD 14.0, OpenBSD 7.9, Minix 3.1.8, HP-UX 11, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
+
+The @code{gettext-h} module has a partial workaround:
+@code{<gettext.h>} supplies the function,
+and makes it a no-op if internationalization is not in use.
 @end itemize
diff --git a/doc/posix-functions/bindtextdomain.texi b/doc/posix-functions/bindtextdomain.texi
index 44018ca7e1..4529080fef 100644
--- a/doc/posix-functions/bindtextdomain.texi
+++ b/doc/posix-functions/bindtextdomain.texi
@@ -28,4 +28,8 @@ Portability problems not fixed by Gnulib:
 @item
 This function is missing on some platforms:
 macOS 14, FreeBSD 14.0, OpenBSD 7.9, Minix 3.1.8, HP-UX 11, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
+
+The @code{gettext-h} module has a partial workaround:
+@code{<gettext.h>} supplies the function,
+and makes it a no-op if internationalization is not in use.
 @end itemize
diff --git a/doc/posix-functions/textdomain.texi b/doc/posix-functions/textdomain.texi
index 6d2a620c2d..27c5df2d9e 100644
--- a/doc/posix-functions/textdomain.texi
+++ b/doc/posix-functions/textdomain.texi
@@ -28,4 +28,8 @@ Portability problems not fixed by Gnulib:
 @item
 This function is missing on some platforms:
 macOS 14, FreeBSD 14.0, OpenBSD 7.9, Minix 3.1.8, HP-UX 11, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
+
+The @code{gettext-h} module has a partial workaround:
+@code{<gettext.h>} supplies the function,
+and makes it a no-op if internationalization is not in use.
 @end itemize
diff --git a/lib/gettext.h b/lib/gettext.h
index d404c0c649..521d69e6b0 100644
--- a/lib/gettext.h
+++ b/lib/gettext.h
@@ -59,6 +59,15 @@
 #  endif
 # endif
 
+/* Like the C cast ((type) (expr)), but do only conversions that an
+   ordinary assignment would do.  This can diagnose invalid arguments
+   better than a cast would.  */
+#  ifdef __cplusplus
+#   define _LIBGETTEXT_FUNCAST(type, expr) static_cast <type> (expr)
+#  else
+#   define _LIBGETTEXT_FUNCAST(type, expr) (type) {(expr)}
+#  endif
+
 /* Disabled NLS.  */
 /* When gcc is used with option -Wformat=2, we need to silence
    "warning: format not a string literal, argument types not checked [-Wformat-nonliteral]"
@@ -173,15 +182,6 @@ dcgettext (const char *domain, const char *msgid, int category)
 
 # else
 
-/* Like the C cast ((type) (expr)), but do only conversions that an
-   ordinary assignment would do.  This can diagnose invalid arguments
-   better than a cast would.  */
-#   ifdef __cplusplus
-#    define _LIBGETTEXT_FUNCAST(type, expr) static_cast <type> (expr)
-#   else
-#    define _LIBGETTEXT_FUNCAST(type, expr) (type) {(expr)}
-#   endif
-
 #  undef gettext
 #  define gettext(Msgid) _LIBGETTEXT_FUNCAST (const char *, Msgid)
 #  undef dgettext
@@ -206,18 +206,18 @@ dcgettext (const char *domain, const char *msgid, int category)
 #  define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
      ((void) _LIBGETTEXT_FUNCAST (int, Category), \
       dngettext (Domainname, Msgid1, Msgid2, N))
-#  undef textdomain
-#  define textdomain(Domainname) _LIBGETTEXT_FUNCAST (const char *, Domainname)
-#  undef bindtextdomain
-#  define bindtextdomain(Domainname, Dirname) \
-     ((void) _LIBGETTEXT_FUNCAST (const char *, Domainname), \
-      _LIBGETTEXT_FUNCAST (const char *, Dirname))
-#  undef bind_textdomain_codeset
-#  define bind_textdomain_codeset(Domainname, Codeset) \
-     ((void) _LIBGETTEXT_FUNCAT (const char *, Domainname), \
-      _LIBGETTEXT_FUNCAT (const char *, Codeset))
-
 # endif
+
+# undef textdomain
+# define textdomain(Domainname) _LIBGETTEXT_FUNCAST (const char *, Domainname)
+# undef bindtextdomain
+# define bindtextdomain(Domainname, Dirname) \
+    ((void) _LIBGETTEXT_FUNCAST (const char *, Domainname), \
+     _LIBGETTEXT_FUNCAST (const char *, Dirname))
+# undef bind_textdomain_codeset
+# define bind_textdomain_codeset(Domainname, Codeset) \
+    ((void) _LIBGETTEXT_FUNCAT (const char *, Domainname), \
+     _LIBGETTEXT_FUNCAT (const char *, Codeset))
 #endif
 
 
diff --git a/tests/test-gettext-h.c b/tests/test-gettext-h.c
index fa0a795c31..c6ad35cd65 100644
--- a/tests/test-gettext-h.c
+++ b/tests/test-gettext-h.c
@@ -27,9 +27,7 @@ main (void)
 {
   const char *s;
 
-#if ENABLE_NLS
   textdomain ("tzlof");
-#endif
 
   s = gettext ("some text");
   if (!streq (s, "some text"))
-- 
2.53.0

Reply via email to