This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] PR48569 clang-format fails to align case label with `switch` with Whitesmith Indentation
ClosedPublic

Authored by MyDeveloperDay on Dec 24 2020, 8:41 AM.

Details

Summary

https://bugs.llvm.org/show_bug.cgi?id=48569

This is a tentative fix which addresses a PR raise regarding Case indentation when working with Whitesmiths Indentation

I could not find online any reference sources as to what the case indentation for Whitesmith's should be (or be allowed to be)

But according to the documentation, we don't obey the rules for Whitesmith's

In particular, the documentation states that this option is to "indent case labels one level from the switch statement. When false, use the same indentation level as for the switch statement."

The behaviour we add here is actually as the TODO in the tests used to state in D67627: Clang-format: Add Whitesmiths indentation style, but when D82016: [clang-format] [PR462254] fix indentation of default and break correctly in whitesmiths style was added and I brought these tests out from being TODO I realized I changed the indentation.

Diff Detail

Event Timeline

MyDeveloperDay requested review of this revision.Dec 24 2020, 8:41 AM
MyDeveloperDay created this revision.

If that's how it's supposed to look, than this patch is fine.

This revision is now accepted and ready to land.Dec 24 2020, 1:53 PM
curdeius accepted this revision.Dec 25 2020, 11:04 AM

It would be great if we had some spec for this style, it gets a bit hard to verify if the formatting is actually what is expected.
Having said that, LGTM if the bug reporter confirms the behaviour is ok.

clang/lib/Format/UnwrappedLineParser.cpp
2248

Nit: the style is named Whitesmiths so I'd expect the variable to match that: small s in the middle, trailing s.

This is the closest I could find thus far http://bitsavers.informatik.uni-stuttgart.de/pdf/chromatics/CGC_7900_C_Programmers_Manual_Mar82.pdf

and the very few examples from the manual show the case is aligned with the switch

This is the closest I could find thus far http://bitsavers.informatik.uni-stuttgart.de/pdf/chromatics/CGC_7900_C_Programmers_Manual_Mar82.pdf

and the very few examples from the manual show the case is aligned with the switch

Nice! Thank you.