clang-format inconsistent behavior

Hi All,

I have found an inconsistent behavior in clang-format. When I format the attached desired.c with the attached .clang-format file (using Clang 4.0 on Windows) I get format_me.c.

I think that the assignment should be consistent, either break the line for all assignments or none of them. Is there an option I have missed or is this behavior intended/not configurable? And if not configurable would we be interested in such a switch?

Regards,

Fabian

desired.c (1.57 KB)

desired.c (1.57 KB)

ATT98132.clang-format (2.58 KB)

Not sure whether I’m unable to use my mail program correctly, but I don’t get a diff between desired.c and format_me.c.

Generally, we’ve thought about trying to make clang-format be more consistent across subsequent statements, but
a) that’s a lot of effort, as clang-format fundamentally works on each statement separately
b) basically all instances (outside of braced lists, which have special support) we’ve seen have been due to code duplication, where the right answer is to refactor the code so the structure is simpler

For example, in your code, I would pull out a wrapper function that takes all the common parameters in a struct, and potentially the other parameters as structs, too. That way, the calls would become reasonably short.

No sorry the error is on my side. I accidentally copied the same file twice. Find the correct files attached to this mail.

I do agree that the interface to the function calls can be improved, but (as you probably know) that is not always possible. I do have two weeks of spare time. Do you think it’s reasonable to implement a switch to specify this behavior as well?

Also do you think it’s possible to achieve this in two weeks? Sounds like this change/adding this option might be complex or even impossible?

Regards,

Fabian

format_me.c (1.47 KB)

desired.c (1.57 KB)

No sorry the error is on my side. I accidentally copied the same file twice. Find the correct files attached to this mail.

I do agree that the interface to the function calls can be improved, but (as you probably know) that is not always possible. I do have two weeks of spare time. Do you think it’s reasonable to implement a switch to specify this behavior as well?

Also do you think it’s possible to achieve this in two weeks? Sounds like this change/adding this option might be complex or even impossible?

I don’t think two weeks will be enough to come up with a solution that gets consensus; if not due to the work required, the latency alone will prevent this (I’d expect this to go through multiple possible architectural revisions)