Bruno Haible <[email protected]> writes:

> Right. It sounds like one needs to define this macro as
>
>   #  define _GL_ATTRIBUTE_ACCESS_READ_ONLY(args) \
>        _GL_ATTRIBUTE_ACCESS_READ_ONLY_AUX args
>   #  define _GL_ATTRIBUTE_ACCESS_READ_ONLY_AUX(...) \
>        __attribute__ ((__access__ (__read_only__, __VA_ARGS__)))

I wrote the attached patch before I saw your message. I assume the AUX
macro would allow the double paranetheses that look more consistent with
other macros?

Collin

>From 7df6419d53be8433ae9c614c02e2f159154bba42 Mon Sep 17 00:00:00 2001
Message-ID: <7df6419d53be8433ae9c614c02e2f159154bba42.1794271258.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Mon, 9 Nov 2026 16:40:18 -0800
Subject: [PATCH] attribute: Fix optional size argument with access attributes.

Reported by Basil L. Contovounesios <[email protected]> in:
<https://lists.gnu.org/r/bug-gnulib/2026-11/msg00046.html>

* m4/gnulib-common.m4 (gl_COMMON_BODY): Remove extra parentheses from
the documentation. Use __VA_ARGS__ for the access attribute maros.
* lib/attribute.h (ATTRIBUTE_ACCESS_READ_ONLY)
(ATTRIBUTE_ACCESS_WRITE_ONLY, ATTRIBUTE_ACCESS_READ_WRITE)
(ATTRIBUTE_ACCESS_NONE): Remove extra parentheses from the
documentation. Remove the arguments from the definition, so we don't
have to use __VA_ARGS__ in the header which may not be supported by the
compiler.
---
 ChangeLog           | 14 ++++++++++++++
 lib/attribute.h     | 16 ++++++++--------
 m4/gnulib-common.m4 | 26 +++++++++++++-------------
 3 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 858ab5d7dd..0530d0fdf4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2026-11-09  Collin Funk  <[email protected]>
+
+	attribute: Fix optional size argument with access attributes.
+	Reported by Basil L. Contovounesios <[email protected]> in:
+	<https://lists.gnu.org/r/bug-gnulib/2026-11/msg00046.html>
+	* m4/gnulib-common.m4 (gl_COMMON_BODY): Remove extra parentheses from
+	the documentation. Use __VA_ARGS__ for the access attribute maros.
+	* lib/attribute.h (ATTRIBUTE_ACCESS_READ_ONLY)
+	(ATTRIBUTE_ACCESS_WRITE_ONLY, ATTRIBUTE_ACCESS_READ_WRITE)
+	(ATTRIBUTE_ACCESS_NONE): Remove extra parentheses from the
+	documentation. Remove the arguments from the definition, so we don't
+	have to use __VA_ARGS__ in the header which may not be supported by the
+	compiler.
+
 2026-11-09  Bruno Haible  <[email protected]>
 
 	doc: More motivation to use the string-desc module.
diff --git a/lib/attribute.h b/lib/attribute.h
index cb69ecbd92..ba9291b7ac 100644
--- a/lib/attribute.h
+++ b/lib/attribute.h
@@ -178,13 +178,13 @@
 /* Applies to: functions.  */
 #define ATTRIBUTE_NONNULL_IF_NONZERO(np, ni) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (np, ni)
 
-/* ATTRIBUTE_ACCESS_READ_ONLY ((N, S)) declares that the Nth argument of
+/* ATTRIBUTE_ACCESS_READ_ONLY (N, S) declares that the Nth argument of
    the function is used to read the referenced object but not to write to it.
-   ATTRIBUTE_ACCESS_WRITE_ONLY ((N, S)) declares that the Nth argument of
+   ATTRIBUTE_ACCESS_WRITE_ONLY (N, S) declares that the Nth argument of
    the function is used to write the referenced object but not to read from it.
-   ATTRIBUTE_ACCESS_READ_WRITE ((N, S)) declares that the Nth argument of
+   ATTRIBUTE_ACCESS_READ_WRITE (N, S) declares that the Nth argument of
    the function is used to both read from and write to the referenced object.
-   ATTRIBUTE_ACCESS_NONE ((N, S)) declares that the Nth argument of the
+   ATTRIBUTE_ACCESS_NONE (N, S) declares that the Nth argument of the
    function is not used to access the referenced object at all.
 
    Each of the ATTRIBUTE_ACCESS_* macros accepts an optional size index S,
@@ -199,10 +199,10 @@
    ATTRIBUTE_NONNULL_IF_NONZERO.
  */
 /* Applies to: functions.  */
-#define ATTRIBUTE_ACCESS_READ_ONLY(args) _GL_ATTRIBUTE_ACCESS_READ_ONLY (args)
-#define ATTRIBUTE_ACCESS_WRITE_ONLY(args) _GL_ATTRIBUTE_ACCESS_WRITE_ONLY (args)
-#define ATTRIBUTE_ACCESS_READ_WRITE(args) _GL_ATTRIBUTE_ACCESS_READ_WRITE (args)
-#define ATTRIBUTE_ACCESS_NONE(args) _GL_ATTRIBUTE_ACCESS_NONE (args)
+#define ATTRIBUTE_ACCESS_READ_ONLY _GL_ATTRIBUTE_ACCESS_READ_ONLY
+#define ATTRIBUTE_ACCESS_WRITE_ONLY _GL_ATTRIBUTE_ACCESS_WRITE_ONLY
+#define ATTRIBUTE_ACCESS_READ_WRITE _GL_ATTRIBUTE_ACCESS_READ_WRITE
+#define ATTRIBUTE_ACCESS_NONE _GL_ATTRIBUTE_ACCESS_NONE
 
 /* The function's return value is a non-NULL pointer.  */
 /* Applies to: functions.  */
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index 119c638e66..c8ae795344 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1,5 +1,5 @@
 # gnulib-common.m4
-# serial 126
+# serial 127
 dnl Copyright (C) 2007-2026 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -357,13 +357,13 @@ AC_DEFUN([gl_COMMON_BODY]
        - In C++, between the 'extern "C"' and the variable's type.
  */
 
-/* _GL_ATTRIBUTE_ACCESS_READ_ONLY ((N, S)) declares that the Nth argument of
+/* _GL_ATTRIBUTE_ACCESS_READ_ONLY (N, S) declares that the Nth argument of
    the function is used to read the referenced object but not to write to it.
-   _GL_ATTRIBUTE_ACCESS_WRITE_ONLY ((N, S)) declares that the Nth argument of
+   _GL_ATTRIBUTE_ACCESS_WRITE_ONLY (N, S) declares that the Nth argument of
    the function is used to write the referenced object but not to read from it.
-   _GL_ATTRIBUTE_ACCESS_READ_WRITE ((N, S)) declares that the Nth argument of
+   _GL_ATTRIBUTE_ACCESS_READ_WRITE (N, S) declares that the Nth argument of
    the function is used to both read from and write to the referenced object.
-   _GL_ATTRIBUTE_ACCESS_NONE ((N, S)) declares that the Nth argument of the
+   _GL_ATTRIBUTE_ACCESS_NONE (N, S) declares that the Nth argument of the
    function is not used to access the referenced object at all.
 
    Each of the _GL_ATTRIBUTE_ACCESS_* macros accepts an optional size index S,
@@ -381,15 +381,15 @@ AC_DEFUN([gl_COMMON_BODY]
 /* Clang does not support these attributes.  */
 #ifndef _GL_ATTRIBUTE_ACCESS_READ_ONLY
 # if _GL_HAS_ATTRIBUTE (access) && ! defined __clang__
-#  define _GL_ATTRIBUTE_ACCESS_READ_ONLY(args) \
-     __attribute__ ((__access__ (__read_only__, args)))
-#  define _GL_ATTRIBUTE_ACCESS_WRITE_ONLY(args) \
-     __attribute__ ((__access__ (__write_only__, args)))
-#  define _GL_ATTRIBUTE_ACCESS_READ_WRITE(args) \
-     __attribute__ ((__access__ (__read_write__, args)))
+#  define _GL_ATTRIBUTE_ACCESS_READ_ONLY(...) \
+     __attribute__ ((__access__ (__read_only__, __VA_ARGS__)))
+#  define _GL_ATTRIBUTE_ACCESS_WRITE_ONLY(...) \
+     __attribute__ ((__access__ (__write_only__, __VA_ARGS__)))
+#  define _GL_ATTRIBUTE_ACCESS_READ_WRITE(...) \
+     __attribute__ ((__access__ (__read_write__, __VA_ARGS__)))
 #  if _GL_GNUC_PREREQ (11, 1)
-#   define _GL_ATTRIBUTE_ACCESS_NONE(args) \
-      __attribute__ ((__access__ (__none__, args)))
+#   define _GL_ATTRIBUTE_ACCESS_NONE(...) \
+      __attribute__ ((__access__ (__none__, __VA_ARGS__)))
 #  else
 #   define _GL_ATTRIBUTE_ACCESS_NONE(args)
 #  endif
-- 
2.56.0

Reply via email to