[cfe-dev] clang-format version incompatibility

Sam McCall via cfe-dev cfe-dev at lists.llvm.org
Wed Oct 14 15:21:25 PDT 2020

On Wed, Oct 14, 2020 at 10:17 PM Renato Golin via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi folks,
> A recent issue [1] on our Github project has highlighted a problem we've
> been having with clang-format.
> Basically, when using different versions of clang-format, with the same
> configuration files [2], we get different results (between 9 and 10).
AFAIK this is in principle expected, clang-format doesn't place a high
prioriy on having stable formatting results across major versions.
This is a tradeoff, requiring formatting to stay stable implies not fixing

In some workflows you can mitigate this by formatting/checking changed
lines, which at least reduces the surface area.
But this is certainly a pain point if you want to enforce style with CI in
a diverse environment.
At work, we enforce the same version of clang-format on all clients and CI.
In a JS-based package I work on, we use the clang-format npm package
<https://www.npmjs.com/package/clang-format> to pin the version.

BTW, someone recently added a clang-format flag to ignore unknown keys in
the config file, which will help in the distant future (when clangd-12 is
the *minimum* version it's safe to assume...)

> clang-format-9:
>     Rule(F f)
>       ->Rule<
>         typename rule_traits<decltype(&F::operator())>::Left,
>         typename rule_traits<decltype(&F::operator())>::Right,
>         F>;
> clang-format-10:
>     Rule(F f) -> Rule<
>       typename rule_traits<decltype(&F::operator())>::Left,
>       typename rule_traits<decltype(&F::operator())>::Right,
>       F>;
This looks like a bugfix to me. I think deduction guides were basically
unsupported and broken in 9.
If I'm right about that, there's certainly no option to restore the old
broken behavior.

> https://github.com/microsoft/verona/blob/master/src/mlir/dialect/VeronaTypes.cc#L487
> clang-format-9:
>       return {MeetType::get(ctx, readElements),
>               JoinType::get(ctx, writeElements)};
> clang-format-10:
>       return {
>         MeetType::get(ctx, readElements), JoinType::get(ctx,
> writeElements)};
Less clear to me what's going on here, but I also suspect a bugfix.
The docs say "Fundamentally, C++11 braced lists are formatted exactly like
function calls would be formatted in their place.".
The clang-format-10 formatting is equivalent to how both clang-format-9 and
10 format `return x(MeetType::get(...), JoinType::get(...));`.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20201015/47142c0b/attachment.html>

More information about the cfe-dev mailing list