Because draft C2x requires using [[maybe_unused]] before a parameter
instead of after, the recent C2x-related changes to Gnulib caused me to
move all uses of _GL_UNUSED_PARAMETER; and while I was at it I changed
it to _GL_ATTRIBUTE_MAYBE_UNUSED FILE thus removing a dependency on the
snippet/unused-parameter module. For example:
SE_SELINUX_INLINE int
-fsetfilecon (int fd _GL_UNUSED_PARAMETER,
- char const *con _GL_UNUSED_PARAMETER)
+fsetfilecon (_GL_ATTRIBUTE_MAYBE_UNUSED int fd,
+ _GL_ATTRIBUTE_MAYBE_UNUSED char const *con)
{ errno = ENOTSUP; return -1; }
A nice property of the change is that the text lines up a bit better.
However, _GL_ATTRIBUTE_MAYBE_UNUSED is too long, so I propose we rename
it to something shorter.
Also, draft C2x lets one write the above function without naming the
parameters, as follows:
SE_SELINUX_INLINE int
fsetfilecon (int, char const *)
{ errno = ENOTSUP; return -1; }
This is nicer than [[maybe_unused]], because it says the arguments are
*definitely* unused instead of merely *maybe* unused, and that allows a
bit more checking of the code.
So, how about the following ideas:
* Rename _GL_ATTRIBUTE_MAYBE_UNUSED to _GL_maybe_unused. Similarly for
_GL_deprecated, _GL_fallthrough, and _GL_nodiscard. As C2x becomes more
popular, it'll be easy to read _GL_deprecated as shorthand for
"[[deprecated]] if supported, empty otherwise". Using lowercase in the
macro names helps readability and will help avoid collisions between
future C2x-like attributes and other Gnulib macros.
* Remove all uses of _GL_UNUSED after arguments in Gnulib, replacing
them with _GL_maybe_unused before arguments. This will support non-GCC
C2x compilers better. Deprecate _GL_UNUSED.
* Define a macro _GL_UNUSED_ARG(TYPE, NAME) that expands to 'TYPE' in
draft C2x, and to '_GL_maybe_unused TYPE NAME' otherwise. That way, one
can write:
SE_SELINUX_INLINE int
fsetfilecon (_GL_UNUSED_ARG (int, fd),
_GL_UNUSED_ARG (char const *, con))
{ errno = ENOTSUP; return -1; }
* Define a macro _GL_UNUSED_ARGNAME(NAME) that expands to NAME if not
draft C2x, empty otherwise. Programs can use this macro for complicated
argument types where _GL_UNUSED_ARG does not suffice, e.g.,
'_GL_maybe_unused int (*_GL_UNUSED_ARGNAME (p)) (int)'.
* Remove the snippet/unused-parameter module as it's not used now.