[all-commits] [llvm/llvm-project] 7ba910: [clang-format] Rewrite how indent is reduced for c...

Emilia Dreamer via All-commits all-commits at lists.llvm.org
Sat Feb 25 02:18:35 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7ba91016c6ad4cb8f82ed154753ddeeb524f9a64
      https://github.com/llvm/llvm-project/commit/7ba91016c6ad4cb8f82ed154753ddeeb524f9a64
  Author: Emilia Dreamer <emilia at rymiel.space>
  Date:   2023-02-25 (Sat, 25 Feb 2023)

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

  Log Message:
  -----------
  [clang-format] Rewrite how indent is reduced for compacted namespaces

The previous version set the indentation directly using IndentForLevel,
however, this has a few caveats, namely:

* IndentForLevel applies to all scopes of the entire program being
  formatted, but this indentation should only be adjusted for scopes
  of namespaces.

* The method it used only set the correct indent amount if one wasn't
  already set for a given level, meaning it didn't work correctly if
  anything with indentation preceded a namespace keyword. This
  includes preprocessing directives if using IndentPPDirectives.

This patch instead reduces the Level of all lines within namespaces
which are compacted by CompactNamespaces. This means they will get
correct indentation using the normal process.

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

Reviewed By: owenpan, MyDeveloperDay, HazardyKnusperkeks

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


  Commit: 393e197cd6eb8942c4eaec3fd6d05bc2e2289212
      https://github.com/llvm/llvm-project/commit/393e197cd6eb8942c4eaec3fd6d05bc2e2289212
  Author: Emilia Dreamer <emilia at rymiel.space>
  Date:   2023-02-25 (Sat, 25 Feb 2023)

  Changed paths:
    M clang/lib/Format/QualifierAlignmentFixer.cpp
    M clang/unittests/Format/QualifierFixerTest.cpp

  Log Message:
  -----------
  [clang-format] Don't move qualifiers past pointers-to-member

Previously, given a pointer-to-member type such as `Foo const Bar::*`,
clang-format would see the `const Bar::` part as a regular type name
with scope resolution operators, and with `QualifierAlignment: Right` it
would attempt to "fix" it, resulting in `Foo Bar::const *`, a syntax
error.

This patch no longer allows qualifiers to be moved across `::*`.

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

Reviewed By: owenpan, MyDeveloperDay, HazardyKnusperkeks

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


Compare: https://github.com/llvm/llvm-project/compare/b0676fb0fb0a...393e197cd6eb


More information about the All-commits mailing list