[all-commits] [llvm/llvm-project] 0090cd: [clang-format] Support inheriting from more than 1...

Zhao Wei Liew via All-commits all-commits at lists.llvm.org
Mon Jan 3 02:36:00 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0090cd4e7a24bedeb24dfe5b3b55167ad74e231e
      https://github.com/llvm/llvm-project/commit/0090cd4e7a24bedeb24dfe5b3b55167ad74e231e
  Author: Zhao Wei Liew <zhaoweiliew at gmail.com>
  Date:   2022-01-03 (Mon, 03 Jan 2022)

  Changed paths:
    M clang/lib/Format/Format.cpp
    M clang/unittests/Format/FormatTest.cpp

  Log Message:
  -----------
  [clang-format] Support inheriting from more than 1 parents in the fallback case

Currently, we are unable to inherit from a chain of parent configs where the outermost parent config has `BasedOnStyle: InheritParentConfig` set. This patch adds a test case for this scenario, and adds support for it.

To illustrate, suppose we have the following directory structure:
```
- e/
  |- .clang-format (BasedOnStyle: InheritParentConfig) <-- outermost config
  |- sub/
    |- .clang-format (BasedOnStyle: InheritParentConfig)
    |- sub/
      |- .clang-format (BasedOnStyle: InheritParentConfig)
      |- code.cpp
```
Now consider what happens when we run `clang-format --style=file /e/sub/sub/code.cpp`.

Without this patch, on a release build, only the innermost config will be applied. On a debug build, clang-format crashes due to an assertion failure.
With this patch, clang-format behaves as we'd expect, applying all 3 configs.

Reviewed By: HazardyKnusperkeks, curdeius

Differential Revision: https://reviews.llvm.org/D116371




More information about the All-commits mailing list