This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Recognize nested blocks

Authored by sstwcw on May 12 2023, 8:37 AM.



Now a block gets recognized as a block if it contains a block.

The special cases we added don't have additional tests because they
are already tested for example in FormatTest.FormatsLambdas and


Diff Detail

Event Timeline

sstwcw created this revision.May 12 2023, 8:37 AM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptMay 12 2023, 8:37 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sstwcw requested review of this revision.May 12 2023, 8:37 AM
sstwcw updated this revision to Diff 521667.May 12 2023, 8:51 AM
  • Remove the special case for operator[], it isn't necessary.

Coincidentally I also sent out a review to fix this issue yesterday, but went with a different approach of trying to scope the ProbablyBracedList logic by just looking at the lbrace previous token.

On this change I like the token annotator tests, and reusing the same stack instead of adding a second one which always has the same size.
But the code changes in D150403 seem to be better, at least I couldn't think directly on something which may not work.


Shouldn't it be called NextBraceIsProbablyLambda (or similar)?


How does this work on

int foo[]={2,5};
int bar[]{2};


SomeClass foo[]={{arg1, whatever}, {arg2, dontcare}};
SomeClass foo[]{{arg1, whatever}, {arg2, dontcare}};




sstwcw abandoned this revision.May 12 2023, 6:20 PM

I like D150403 better.