[all-commits] [llvm/llvm-project] 3e333c: [clang-format] Fix PointerAlignmentRight with Alig...

Gerhard Gappmeier via All-commits all-commits at lists.llvm.org
Thu Jun 3 08:55:14 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3e333cc82e42e1e2ecc974d896489eebe1a5edc2
      https://github.com/llvm/llvm-project/commit/3e333cc82e42e1e2ecc974d896489eebe1a5edc2
  Author: Gerhard Gappmeier <gerhard.gappmeier at ascolab.com>
  Date:   2021-06-03 (Thu, 03 Jun 2021)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Format/WhitespaceManager.cpp
    M clang/unittests/Format/FormatTest.cpp

  Log Message:
  -----------
  [clang-format] Fix PointerAlignmentRight with AlignConsecutiveDeclarations

This re-applies the old patch D27651, which was never landed, into the
latest "main" branch, without understanding the code. I just applied
the changes "mechanically" and made it compiling again.

This makes the right pointer alignment working as expected.
Fixes https://llvm.org/PR27353

For instance

const char* const* v1;
float const* v2;
SomeVeryLongType const& v3;

was formatted as

const char *const *     v1;
float const *           v2;
SomeVeryLongType const &v3;

This patch keep the *s or &s aligned to the right, next to their variable.
The above example is now formatted as

const char *const      *v1;
float const            *v2;
SomeVeryLongType const &v3;

It is a pity that this still does not work with clang-format in 2021,
even though there was a fix available in 2016. IMHO right pointer alignment
is the default case in C, because syntactically the pointer belongs to the
variable.

See

int* a, b, c; // wrong, just the 1st variable is a pointer

vs.

int *a, *b, *c; // right

Prominent example is the Linux kernel coding style.

Some styles argue the left pointer alignment is better and declaration
lists as shown above should be avoided. That's ok, as different projects
can use different styles, but this important style should work too.

I hope that somebody that has a better understanding about the code,
can take over this patch and land it into main.

For now I must maintain this fork to make it working for our projects.

Cheers,
Gerhard.

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


  Commit: 6f605b8d0bc1c19dccc7a6c248b4fa60e6f7fde3
      https://github.com/llvm/llvm-project/commit/6f605b8d0bc1c19dccc7a6c248b4fa60e6f7fde3
  Author: Gerhard Gappmeier <gerhard.gappmeier at ascolab.com>
  Date:   2021-06-03 (Thu, 03 Jun 2021)

  Changed paths:
    M clang/docs/ClangFormatStyleOptions.rst
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Format/Format.h
    M clang/lib/Format/Format.cpp
    M clang/lib/Format/UnwrappedLineFormatter.cpp
    M clang/unittests/Format/FormatTest.cpp

  Log Message:
  -----------
  [clang-format] Add PPIndentWidth option

This allows to set a different indent width for preprocessor statements.

Example:

 #ifdef __linux_
 # define FOO
 #endif

int main(void)
{
    return 0;
}

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


Compare: https://github.com/llvm/llvm-project/compare/12db09d7f3bb...6f605b8d0bc1


More information about the All-commits mailing list