From: Junio C Hamano <gitster@pobox.com>
To: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH] mingw: avoid the comma operator
Date: Mon, 17 Nov 2025 14:16:34 -0800 [thread overview]
Message-ID: <xmqqy0o4gv99.fsf@gitster.g> (raw)
In-Reply-To: <pull.2007.git.1763412374866.gitgitgadget@gmail.com> (Johannes Schindelin via GitGitGadget's message of "Mon, 17 Nov 2025 20:46:14 +0000")
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> The pattern `return errno = ..., -1;` is observed several times in
> `compat/mingw.c`. It has served us well over the years, but now clang
> starts complaining:
>
> compat/mingw.c:723:24: error: possible misuse of comma operator here [-Werror,-Wcomma]
> 723 | return errno = ENOSYS, -1;
> | ^
>
> See for example this failing workflow run:
> https://github.com/git-for-windows/git-sdk-arm64/actions/runs/15457893907/job/43513458823#step:8:201
>
> Let's appease clang (and also reduce the use of the no longer common
> comma operator).
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> mingw: avoid the comma operator
>
> I wonder how many more times I will deal with the comma operator...
;-)
> /* only these flags are supported */
> - if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND))
> - return errno = ENOSYS, -1;
> + if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND)) {
> + errno = ENOSYS;
> + return -1;
> + }
Good riddance. It indeed is somewhat hard to read, especially
because it may not be apparent to readers how "A = B, C" binds
(answer: B gets assigned to A and then the whole thing yields C).
I wonder if
return (errno = ENOSYS), -1;
is accepted by the compiler, but in these error handling we do not
have to be cute, and updated code that is both simple and stupid
reads very well.
Will queue. Thanks.
next prev parent reply other threads:[~2025-11-17 22:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-17 20:46 [PATCH] mingw: avoid the comma operator Johannes Schindelin via GitGitGadget
2025-11-17 22:16 ` Junio C Hamano [this message]
2025-11-18 9:49 ` Jeff King
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqy0o4gv99.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johannes.schindelin@gmx.de \
/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 NNTP newsgroup(s).