From: Paul Eggert <eggert@cs.ucla.edu>
To: Gnulib bugs <bug-gnulib@gnu.org>
Subject: Using C2x attributes more effectively in Gnulib
Date: Sat, 31 Jul 2021 12:52:50 -0700 [thread overview]
Message-ID: <0ed0a5a4-ed41-7d40-1c31-f422b55e7ab3@cs.ucla.edu> (raw)
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.
next reply other threads:[~2021-07-31 19:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-31 19:52 Paul Eggert [this message]
2021-08-08 1:40 ` Using C2x attributes more effectively in Gnulib Bruno Haible
2021-08-09 10:08 ` Paul Eggert
2021-08-22 13:33 ` Bruno Haible
2021-08-22 20:05 ` gnulib-common.m4: Use C2x [[maybe_unused]] when possible Bruno Haible
2021-08-23 1:06 ` snippet/unused-parameter: Mark unused module obsolete Bruno Haible
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0ed0a5a4-ed41-7d40-1c31-f422b55e7ab3@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).