[all-commits] [llvm/llvm-project] e9ed1a: [clang-format] Correctly annotate designated initi...

Emilia Kond via All-commits all-commits at lists.llvm.org
Thu Sep 7 12:23:18 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e9ed1aa9cd867938cd05fe76df57eb505591e81a
      https://github.com/llvm/llvm-project/commit/e9ed1aa9cd867938cd05fe76df57eb505591e81a
  Author: Emilia Kond <emilia at rymiel.space>
  Date:   2023-09-07 (Thu, 07 Sep 2023)

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

  Log Message:
  -----------
  [clang-format] Correctly annotate designated initializer with PP if (#65409)

When encountering braces, such as those of a designated initializer,
clang-format scans ahead to see what is contained within the braces. If
it found a statement, like an if-statement of for-loop, it would deem
the braces as not an initializer, but as a block instead.

However, this heuristic incorrectly included a preprocessor `#if` line
as an if-statement. This manifested in strange results and discrepancies
between `#ifdef` and `#if defined`.

With this patch, `if` is now ignored if it is preceeded by `#`.

Fixes most of https://github.com/llvm/llvm-project/issues/56685




More information about the All-commits mailing list