[cfe-dev] Repeated clang-format'ting keeps changing code / use of clang-format in CI

Sebastian Pipping via cfe-dev cfe-dev at lists.llvm.org
Sat Aug 3 14:55:50 PDT 2019


Hello Nico,


On 29.07.19 15:16, Nico Weber wrote:
> As you can see by the weird "default : break" at the end, clang-format
> gets confused about the whole switch statement. It looks like the macros
> confuse it. Just adding semicolons after it is sufficient to unconfuse it:
> 
> [..]
>   LEAD_CASE(2); LEAD_CASE(3); LEAD_CASE(4);
> [..]
> 
> If you're able to change expat's source, this might be a good approach.

interesting idea!


> Else, you can explicitly tell clang-format the name of macros that
> should be handled as statements in your .clang-format file like so:
> 
> StatementMacros: ['LEAD_CASE']

Good to know!


> You can fix this by doing `XCS("foo" "bar")` (with a linebreak in
> between foo and bar) instead of `XCS("foo") XCS("bar")`. Semantically
> they do the same thing as far as I can tell, but clang-format does much
> better with the first form.

Things get interesting here because XCS is either

  # define XCS(s) _XCS(s)
  # define _XCS(s) L ## s

or

  # define XCS(s) s

depending of macro XML_UNICODE_WCHAR_T to turn string literals into
wide or narrow string literals.  For the first version, XCS("foo" "bar")
results in invalid C syntax, mixing wide L"foo" with narrow "bar".  As a
result, I needed to turn off BreakStringLiterals altogether for now.

Best



Sebastian



More information about the cfe-dev mailing list