* lib/attribute.h (UNNAMED): New macro, like _GL_UNNAMED.
When applicable, prefer this new macro to MAYBE_UNUSED.
---
 ChangeLog           |  6 ++++++
 doc/attribute.texi  | 18 ++++++++++++++++++
 lib/attribute.h     | 16 +++++++++++++++-
 lib/bitset.c        |  2 +-
 lib/bitset/array.c  |  8 +++-----
 lib/bitset/list.c   |  4 ++--
 lib/bitset/stats.c  |  2 +-
 lib/bitset/table.c  |  2 +-
 lib/bitset/vector.c |  7 +++----
 lib/file-has-acl.c  | 11 +++++------
 lib/savedir.c       |  2 +-
 11 files changed, 56 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d24d42af21..798b35677c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-12-24  Paul Eggert  <[email protected]>
+
+       attribute: new C macro UNNAMED
+       * lib/attribute.h (UNNAMED): New macro, like _GL_UNNAMED.
+       When applicable, prefer this new macro to MAYBE_UNUSED.
+
 2025-12-23  Paul Eggert  <[email protected]>
 
        New C macro _GL_UNNAMED
diff --git a/doc/attribute.texi b/doc/attribute.texi
index a60db6e25b..92a9441b72 100644
--- a/doc/attribute.texi
+++ b/doc/attribute.texi
@@ -49,3 +49,21 @@ be defined to @code{[[deprecated]]} etc.@: on C23 platforms.
 Also, these exceptional macros should be placed at the start of
 function declarations, whereas the @code{ATTRIBUTE_*} macros can be
 placed at the end.
+
+The module also defines the macro @code{UNNAMED},
+designed for function parameters that are never used,
+whereas the @code{MAYBE_UNUSED} attribute is better suited for parameters
+that might or might not be unused depending on preprocessor macro settings.
+For example:
+
+@example
+int
+f (int a, MAYBE_UNUSED int b, int UNNAMED (c))
+@{
+  int r = a;
+#ifdef B_FEATURE
+  r |= b;
+#endif
+  return r;
+@}
+@end example
diff --git a/lib/attribute.h b/lib/attribute.h
index 60ec5391b6..eded1543a5 100644
--- a/lib/attribute.h
+++ b/lib/attribute.h
@@ -89,7 +89,7 @@
    _GL_ATTRIBUTE_NONNULL_IF_NONZERO, _GL_ATTRIBUTE_NONSTRING,
    _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PACKED, _GL_ATTRIBUTE_PURE,
    _GL_ATTRIBUTE_REPRODUCIBLE, _GL_ATTRIBUTE_RETURNS_NONNULL,
-   _GL_ATTRIBUTE_SENTINEL, _GL_ATTRIBUTE_UNSEQUENCED.  */
+   _GL_ATTRIBUTE_SENTINEL, _GL_ATTRIBUTE_UNSEQUENCED, _GL_UNNAMED.  */
 #if !_GL_CONFIG_H_INCLUDED
  #error "Please include config.h first."
 #endif
@@ -338,4 +338,18 @@
 #define ATTRIBUTE_MAY_ALIAS _GL_ATTRIBUTE_MAY_ALIAS
 
 
+/* ==================== Unnamed function parameters ======================== */
+
+/* Although UNNAMED is not an attribute, it is related to MAYBE_UNUSED
+   and so is defined here for convenience.  */
+
+/* UNNAMED (ID) is the "name" of an unnamed function parameter.
+   Each of the function's unnamed parameters should have a unique "name".
+   The "name" cannot be used.  This ports both to C17 and earlier, which
+   lack unnamed parameters, and to C++ and later C, which have them.  */
+/* Applies to:
+     - function parameters.  */
+#define UNNAMED(id) _GL_UNNAMED (id)
+
+
 #endif /* _GL_ATTRIBUTE_H */
diff --git a/lib/bitset.c b/lib/bitset.c
index 764ec3251a..8a93e40430 100644
--- a/lib/bitset.c
+++ b/lib/bitset.c
@@ -94,7 +94,7 @@ bitset_init (bitset bset, bitset_bindex n_bits, enum 
bitset_type type)
    specified by ATTR.  For variable size bitsets, N_BITS is only a
    hint and may be zero.  */
 enum bitset_type
-bitset_type_choose (MAYBE_UNUSED bitset_bindex n_bits, unsigned attr)
+bitset_type_choose (bitset_bindex UNNAMED (n_bits), unsigned attr)
 {
   /* Check attributes.  */
   if (attr & BITSET_FIXED && attr & BITSET_VARIABLE)
diff --git a/lib/bitset/array.c b/lib/bitset/array.c
index 817dbaaac9..62c1526961 100644
--- a/lib/bitset/array.c
+++ b/lib/bitset/array.c
@@ -84,7 +84,7 @@ abitset_small_list (bitset src, bitset_bindex *list,
 
 /* Set bit BITNO in bitset DST.  */
 static void
-abitset_set (MAYBE_UNUSED bitset dst, MAYBE_UNUSED bitset_bindex bitno)
+abitset_set (bitset UNNAMED (dst), bitset_bindex UNNAMED (bitno))
 {
   /* This should never occur for abitsets since we should always hit
      the cache.  It is likely someone is trying to access outside the
@@ -95,8 +95,7 @@ abitset_set (MAYBE_UNUSED bitset dst, MAYBE_UNUSED 
bitset_bindex bitno)
 
 /* Reset bit BITNO in bitset DST.  */
 static void
-abitset_reset (MAYBE_UNUSED bitset dst,
-               MAYBE_UNUSED bitset_bindex bitno)
+abitset_reset (bitset UNNAMED (dst), bitset_bindex UNNAMED (bitno))
 {
   /* This should never occur for abitsets since we should always hit
      the cache.  It is likely someone is trying to access outside the
@@ -106,8 +105,7 @@ abitset_reset (MAYBE_UNUSED bitset dst,
 
 /* Test bit BITNO in bitset SRC.  */
 static bool
-abitset_test (MAYBE_UNUSED bitset src,
-              MAYBE_UNUSED bitset_bindex bitno)
+abitset_test (bitset UNNAMED (src), bitset_bindex UNNAMED (bitno))
 {
   /* This should never occur for abitsets since we should always
      hit the cache.  */
diff --git a/lib/bitset/list.c b/lib/bitset/list.c
index c830933dc2..dc47cb6d16 100644
--- a/lib/bitset/list.c
+++ b/lib/bitset/list.c
@@ -1235,7 +1235,7 @@ static struct bitset_vtable lbitset_vtable = {
 
 /* Return size of initial structure.  */
 size_t
-lbitset_bytes (MAYBE_UNUSED bitset_bindex n_bits)
+lbitset_bytes (bitset_bindex UNNAMED (n_bits))
 {
   return sizeof (struct lbitset_struct);
 }
@@ -1243,7 +1243,7 @@ lbitset_bytes (MAYBE_UNUSED bitset_bindex n_bits)
 
 /* Initialize a bitset.  */
 bitset
-lbitset_init (bitset bset, MAYBE_UNUSED bitset_bindex n_bits)
+lbitset_init (bitset bset, bitset_bindex n_bits)
 {
   BITSET_NBITS_ (bset) = n_bits;
   bset->b.vtable = &lbitset_vtable;
diff --git a/lib/bitset/stats.c b/lib/bitset/stats.c
index 738c76a790..e0ae1b8197 100644
--- a/lib/bitset/stats.c
+++ b/lib/bitset/stats.c
@@ -208,7 +208,7 @@ bitset_stats_print_1 (FILE *file, const char *name,
 
 /* Print all bitset statistics to FILE.  */
 static void
-bitset_stats_print (FILE *file, MAYBE_UNUSED bool verbose)
+bitset_stats_print (FILE *file, bool UNNAMED (verbose))
 {
   if (!bitset_stats_info)
     return;
diff --git a/lib/bitset/table.c b/lib/bitset/table.c
index 71fe200c23..6a3f0a3872 100644
--- a/lib/bitset/table.c
+++ b/lib/bitset/table.c
@@ -1137,7 +1137,7 @@ static struct bitset_vtable tbitset_vtable = {
 
 /* Return size of initial structure.  */
 size_t
-tbitset_bytes (MAYBE_UNUSED bitset_bindex n_bits)
+tbitset_bytes (bitset_bindex UNNAMED (n_bits))
 {
   return sizeof (struct tbitset_struct);
 }
diff --git a/lib/bitset/vector.c b/lib/bitset/vector.c
index 3c8a0203b1..66882130aa 100644
--- a/lib/bitset/vector.c
+++ b/lib/bitset/vector.c
@@ -126,7 +126,7 @@ vbitset_set (bitset dst, bitset_bindex bitno)
 
 /* Reset bit BITNO in bitset DST.  */
 static void
-vbitset_reset (MAYBE_UNUSED bitset dst, MAYBE_UNUSED bitset_bindex bitno)
+vbitset_reset (bitset UNNAMED (dst), bitset_bindex UNNAMED (bitno))
 {
   /* We must be accessing outside the cache so the bit is
      zero anyway.  */
@@ -135,8 +135,7 @@ vbitset_reset (MAYBE_UNUSED bitset dst, MAYBE_UNUSED 
bitset_bindex bitno)
 
 /* Test bit BITNO in bitset SRC.  */
 static bool
-vbitset_test (MAYBE_UNUSED bitset src,
-              MAYBE_UNUSED bitset_bindex bitno)
+vbitset_test (bitset UNNAMED (src), bitset_bindex UNNAMED (bitno))
 {
   /* We must be accessing outside the cache so the bit is
      zero anyway.  */
@@ -964,7 +963,7 @@ static struct bitset_vtable vbitset_vtable = {
 
 
 size_t
-vbitset_bytes (MAYBE_UNUSED bitset_bindex n_bits)
+vbitset_bytes (bitset_bindex UNNAMED (n_bits))
 {
   return sizeof (struct vbitset_struct);
 }
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c
index d5a52b5b2f..8d20504f8b 100644
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -79,16 +79,15 @@ smack_smackfs_path (void)
   return NULL;
 }
 static ssize_t
-smack_new_label_from_path (MAYBE_UNUSED const char *path,
-                           MAYBE_UNUSED const char *xattr,
-                           MAYBE_UNUSED int follow, MAYBE_UNUSED char **label)
+smack_new_label_from_path (const char *UNNAMED (path),
+                           const char *UNNAMED (xattr),
+                           int UNNAMED (follow), char **UNNAMED (label))
 {
   return -1;
 }
 static ssize_t
-smack_new_label_from_file (MAYBE_UNUSED int fd,
-                           MAYBE_UNUSED const char *xattr,
-                           MAYBE_UNUSED char **label)
+smack_new_label_from_file (int UNNAMED (fd), const char *UNNAMED (xattr),
+                           char **UNNAMED (label))
 {
   return -1;
 }
diff --git a/lib/savedir.c b/lib/savedir.c
index 670346f0eb..7d8e207cc7 100644
--- a/lib/savedir.c
+++ b/lib/savedir.c
@@ -74,7 +74,7 @@ direntry_cmp_name (void const *a, void const *b, void *arg)
 /* Compare the inode numbers of two directory entries */
 
 static int
-direntry_cmp_inode (void const *a, void const *b, MAYBE_UNUSED void *arg)
+direntry_cmp_inode (void const *a, void const *b, void *UNNAMED (arg))
 {
   direntry_t const *dea = a;
   direntry_t const *deb = b;
-- 
2.51.0


Reply via email to