[PATCH] D42729: clang-format: Fix formatting of function body followed by semicolon

Francois Ferrand via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 31 05:59:40 PST 2018


Typz added a comment.

There are actually other cases, e.g. with macros "containing" the semicolon:

  void abort() {
    FOO()
    BAR()
  };

gets reformatted to this (still wrong with this patch, but the space after the parenthesis is added):

  void abort(){ FOO() BAR() };

And also this one (though it may be slightly different, there is no semicolon here):

  void abort() {
    FOO()
  }
  uint32_t bar() {}

gets reformatted to:

  void abort(){ FOO() BAR() } uint32_t bar() {}

IMO the "real" fix would be to somehow let `TokenAnnotator::calculateFormattingInformation` split the current UnwrappedLine/AnnotatedLine, so that the 'end of the line' could be unwrapped properly: this would also allow keeping the invariant, and just implement some kind of backtracking. But it may be tricky to get the state right; maybe adding some child lines instead of just adding the lines may be simpler?


Repository:
  rC Clang

https://reviews.llvm.org/D42729





More information about the cfe-commits mailing list