This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix PointerAlignment within lambdas in a multi-variable declaration statement.
ClosedPublic

Authored by curdeius on Feb 12 2022, 12:19 PM.

Details

Diff Detail

Event Timeline

curdeius requested review of this revision.Feb 12 2022, 12:19 PM
curdeius created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2022, 12:19 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

What about if?

This revision is now accepted and ready to land.Feb 12 2022, 12:57 PM
curdeius updated this revision to Diff 408213.EditedFeb 12 2022, 1:05 PM

Rebase on top of D119649, add a similar case with a leading comment.

Without it (and if startsWithLoopWithInitializer didn't use startsWith that skips comments), there would be a different spacing of multi-variable initializers in loops, e.g. (-expected, +incorrect):

-/*comment*/ for (int *p, *q; p != q; p = p->next) {
+/*comment*/ for (int* p, *q; p != q; p = p->next) {

What about if?

True, I need to fix them in D119649 too.
And I think that I'll split the fix for while loops from this revision.

Does any C++ standard support init statements in while loops?

curdeius planned changes to this revision.Feb 12 2022, 1:39 PM

Does any C++ standard support init statements in while loops?

Argh, I initially thought about if statements and then somehow my brain turned it into while.
You're right, there are only if and for statements with initializers (C++20 added initializers for ranged-base for loops).

Let me split this revision (fixing if and not while) and clear things up.

curdeius updated this revision to Diff 408217.Feb 12 2022, 1:54 PM

Split from and rebase on top of D119650.

This revision is now accepted and ready to land.Feb 12 2022, 1:54 PM
owenpan added inline comments.Feb 12 2022, 2:54 PM
clang/unittests/Format/FormatTest.cpp
8415–8417

Same as lines 8412-8414.

curdeius added inline comments.Feb 13 2022, 12:23 AM
clang/unittests/Format/FormatTest.cpp
8415–8417

Some problem with the patch, it wasn't in this commit. Will fix after landing other revisions.

Does any C++ standard support init statements in while loops?

I actually thought there was. But that was a mistake. :)

clang/lib/Format/TokenAnnotator.cpp
31–33

But switch can have such a statement.

curdeius updated this revision to Diff 408289.Feb 13 2022, 12:42 PM
curdeius marked an inline comment as done.

Rebased.

curdeius marked an inline comment as done.Feb 13 2022, 12:42 PM
owenpan accepted this revision.Feb 13 2022, 1:52 PM