]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
attribute: new C macro UNNAMED
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 24 Dec 2025 08:08:50 +0000 (00:08 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 24 Dec 2025 08:12:18 +0000 (00:12 -0800)
* lib/attribute.h (UNNAMED): New macro, like _GL_UNNAMED.
When applicable, prefer this new macro to MAYBE_UNUSED.

ChangeLog
doc/attribute.texi
lib/attribute.h
lib/bitset.c
lib/bitset/array.c
lib/bitset/list.c
lib/bitset/stats.c
lib/bitset/table.c
lib/bitset/vector.c
lib/file-has-acl.c
lib/savedir.c

index d24d42af21570a23e2af176b8c6e0f1ff19c0561..798b35677c062e262725efbbc1af40f181369713 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-12-24  Paul Eggert  <eggert@cs.ucla.edu>
+
+       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  <eggert@cs.ucla.edu>
 
        New C macro _GL_UNNAMED
index a60db6e25b189ccbf9f6115f8694b4442c12928a..92a9441b72bcc37e2bc640b3f59875b709b5d931 100644 (file)
@@ -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
index 60ec5391b6c7c8d33d5d4bf9985239d95af02cb8..eded1543a50e30a180e1ca08f0fcd5679603dfcc 100644 (file)
@@ -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
 #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 */
index 764ec3251a7814a29a6b306e8f3247399d854486..8a93e4043089918b0edc16409a2cfe3abdb91ab9 100644 (file)
@@ -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)
index 817dbaaac96003d42fc639d50a2e699c66a1148d..62c15269614904aa81a1c072dfd0b6e4527d5dfc 100644 (file)
@@ -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.  */
index c830933dc2ff99c4744ea11e717db949a38cd171..dc47cb6d16147fcb8ffb4b8f86739d7cf7896155 100644 (file)
@@ -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;
index 738c76a7902399ddaa7112df925ff593831bc188..e0ae1b81970c47dd30ee7fdfec733f5f99bb6382 100644 (file)
@@ -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;
index 71fe200c231c14d4ea04de37e5233281c45aa52c..6a3f0a387243ce10ff178accba25b580de8434f8 100644 (file)
@@ -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);
 }
index 3c8a0203b1063339c29eb003e799b837fe0b4265..66882130aa535ee32c23c4d94ffb14abf5b4d2c1 100644 (file)
@@ -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);
 }
index d5a52b5b2f88545c798cc114d99a90df378aa1c8..8d20504f8b975818198d33f510fe9bfe18aea0ee 100644 (file)
@@ -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;
 }
index 670346f0eb1daff2ccdbf1a2e4b203a1423f6b98..7d8e207cc767cae5038d8ae70419225ea5699998 100644 (file)
@@ -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;