[all-commits] [llvm/llvm-project] 063e3f: [clang-format] Skip PP directives when determining...

Emilia Kond via All-commits all-commits at lists.llvm.org
Thu Nov 2 20:51:33 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 063e3fe648533004e6970ab767ece845e3c0afb1
      https://github.com/llvm/llvm-project/commit/063e3fe648533004e6970ab767ece845e3c0afb1
  Author: Emilia Kond <emilia at rymiel.space>
  Date:   2023-11-03 (Fri, 03 Nov 2023)

  Changed paths:
    M clang/lib/Format/UnwrappedLineParser.cpp
    M clang/unittests/Format/TokenAnnotatorTest.cpp

  Log Message:
  -----------
  [clang-format] Skip PP directives when determining brace kind (#69473)

Pull request #65409 changed the brace kind heuristic to not treat a
preprocessor if directive as a in statement, however, this caused some
regressions.

If the contents of a brace don't immediately determine the brace kind,
the heuristic will look at the characters immediately before and after
the closing brace to determine the brace type.

Unfortunately, if the closing brace was preceded by a preprocessor
directive, for example `#endif`, the preceding token was `endif`, seen
as just an identifier, so the braces were understood as a braced list.

This patch fixes this behaviour by skipping all preprocessor directives
when calculating brace types. Comments were already being skipped, so
now preprocessor lines are skipped alongside comments.

Fixes https://github.com/llvm/llvm-project/issues/68404




More information about the All-commits mailing list