[PATCH] gettext: more-consistent no-op macros

Paul Eggert <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <[email protected]>
* lib/gettext.h (gettext, dgettext, dcgettext): When defining
no-op macros, be more consistent about always "using" the
arguments; this pacifies clang -Wunused-parameter when
--disable-nls is used.  Also, be more consistent about using
compound literals rather than casts, for better type checking.
---
 ChangeLog     |  9 +++++++++
 lib/gettext.h | 20 +++++++++++---------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5caceed13e..6690d65c97 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2026-08-24  Paul Eggert  <[email protected]>
+
+	gettext: more-consistent no-op macros
+	* lib/gettext.h (gettext, dgettext, dcgettext): When defining
+	no-op macros, be more consistent about always "using" the
+	arguments; this pacifies clang -Wunused-parameter when
+	--disable-nls is used.  Also, be more consistent about using
+	compound literals rather than casts, for better type checking.
+
 2026-08-22  Paul Eggert  <[email protected]>
 
 	announce-gen: decrease clutter in output of advice
diff --git a/lib/gettext.h b/lib/gettext.h
index 4238340305..8ae3885fd7 100644
--- a/lib/gettext.h
+++ b/lib/gettext.h
@@ -162,11 +162,13 @@ dcgettext (const char *domain, const char *msgid, int category)
 #  endif
 # elif defined __clang__
 #  undef gettext
-#  define gettext(Msgid) ((const char *) (Msgid))
+#  define gettext(Msgid) ((const char *) {(Msgid)})
 #  undef dgettext
-#  define dgettext(Domainname, Msgid) gettext (Msgid)
+#  define dgettext(Domainname, Msgid) \
+     ((void) (const char *) {(Domainname)}, gettext (Msgid))
 #  undef dcgettext
-#  define dcgettext(Domainname, Msgid, Category) dgettext (Domainname, Msgid)
+#  define dcgettext(Domainname, Msgid, Category) \
+     ((void) (int) {(Category)}, dgettext (Domainname, Msgid))
 # else
 /* The conversions to 'const char *' via compound literals serve the purpose
    of producing warnings for invalid uses of the value returned from these
@@ -186,13 +188,13 @@ dcgettext (const char *domain, const char *msgid, int category)
 # if (defined __GNUC__ && defined __cplusplus) || defined __clang__
 #  undef ngettext
 #  define ngettext(Msgid1, Msgid2, N) \
-     ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
+     ((N) == 1 ? (const char *) {(Msgid1)} : (const char *) {(Msgid2)})
 #  undef dngettext
 #  define dngettext(Domainname, Msgid1, Msgid2, N) \
-     ngettext (Msgid1, Msgid2, N)
+     ((void) (const char *) {(Domainname)}, ngettext (Msgid1, Msgid2, N))
 #  undef dcngettext
 #  define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
-     dngettext (Domainname, Msgid1, Msgid2, N)
+     ((void) (int) {(Category)}, dngettext (Domainname, Msgid1, Msgid2, N))
 # elif defined __GNUC__ && !defined __cplusplus
 /* Silence -Wuseless-cast warnings.  */
 #  if __GNUC__ >= 14
@@ -200,13 +202,13 @@ dcgettext (const char *domain, const char *msgid, int category)
 #  endif
 #  undef ngettext
 #  define ngettext(Msgid1, Msgid2, N) \
-     ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
+     ((N) == 1 ? (const char *) {(Msgid1)} : (const char *) {(Msgid2)})
 #  undef dngettext
 #  define dngettext(Domainname, Msgid1, Msgid2, N) \
-     ((void) (const char *) (Domainname), ngettext (Msgid1, Msgid2, N))
+     ((void) (const char *) {(Domainname)}, ngettext (Msgid1, Msgid2, N))
 #  undef dcngettext
 #  define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
-     ((void) (int) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
+     ((void) (int) {(Category)}, dngettext (Domainname, Msgid1, Msgid2, N))
 # else
 /* The conversions to 'const char *' via compound literals serve the purpose
    of producing warnings for invalid uses of the value returned from these
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.