[PATCH] D116316: [clang-format] Add an experimental option to remove optional control statement braces in LLVM C++ code

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 30 15:31:05 PST 2021


owenpan added inline comments.


================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2303
+      assert(IfRightBrace->MatchingParen == IfLeftBrace);
+      IfLeftBrace->MatchingParen = nullptr;
+      IfRightBrace->MatchingParen = nullptr;
----------------
HazardyKnusperkeks wrote:
> owenpan wrote:
> > HazardyKnusperkeks wrote:
> > > Why null that?
> > `MatchingParen` is used to flag braces that may be optional. If it turns out that they should not be removed, we must reset it. Otherwise, the test case on line 23314 in FormatTest.cpp below would fail.
> Is `MatchingParen` for (if) braces null before this patch? Because I would expect that always to be set, if there is a matching brace and maybe base patches on that assumption.
Yes, it's not set until it's in the token annotator. That's why I added the assertion in the annotator.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116316/new/

https://reviews.llvm.org/D116316



More information about the cfe-commits mailing list