Skip to content

Conversation

@dscho
Copy link
Member

@dscho dscho commented Nov 17, 2025

I wonder how many more times I will deal with the comma operator...

cc: Jeff King peff@peff.net

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>
@dscho dscho self-assigned this Nov 17, 2025
@dscho
Copy link
Member Author

dscho commented Nov 17, 2025

/submit

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 17, 2025

Submitted as pull.2007.git.1763412374866.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2007/dscho/mingw-avoid-the-comma-operator-5660--v1

To fetch this version to local tag pr-2007/dscho/mingw-avoid-the-comma-operator-5660--v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2007/dscho/mingw-avoid-the-comma-operator-5660--v1

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 17, 2025

On the Git mailing list, Junio C Hamano wrote (reply to this):

"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.

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 17, 2025

This patch series was integrated into seen via git@06ac4b0.

@gitgitgadget gitgitgadget bot added the seen label Nov 17, 2025
@gitgitgadget
Copy link

gitgitgadget bot commented Nov 18, 2025

On the Git mailing list, Jeff King wrote (reply to this):

On Mon, Nov 17, 2025 at 02:16:34PM -0800, Junio C Hamano wrote:

> >  	/* 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.

Agreed that we are best avoiding comma operators when we can. There is
one spot where we use it, though, and I haven't figured out a good way
around it: in the error() macro wrapper.

I guess it does not cause the same compiler complaints because there is
no assignment in it. So if nobody is complaining, we can just avert our
eyes when looking at the macro. :)

-Peff

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 18, 2025

User Jeff King <peff@peff.net> has been added to the cc: list.

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 18, 2025

This patch series was integrated into seen via git@41a27af.

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 18, 2025

This branch is now known as js/mingw-assign-comma-fix.

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 18, 2025

This patch series was integrated into seen via git@51e3f26.

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 19, 2025

This patch series was integrated into seen via git@29bebc7.

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 19, 2025

This patch series was integrated into next via git@d1a5807.

@gitgitgadget gitgitgadget bot added the next label Nov 19, 2025
@gitgitgadget
Copy link

gitgitgadget bot commented Nov 20, 2025

There was a status update in the "New Topics" section about the branch js/mingw-assign-comma-fix on the Git mailing list:

The "return errno = EFOO, -1" construct, which is heavily used in
compat/mingw.c and triggers warnings under "-Wcomma", has been
rewritten to avoid the warnings.

Will merge to 'master'.
source: <pull.2007.git.1763412374866.gitgitgadget@gmail.com>

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 20, 2025

This patch series was integrated into seen via git@81651aa.

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 21, 2025

This patch series was integrated into seen via git@fe05518.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant