[all-commits] [llvm/llvm-project] d06b92: [clang-format] Fix a bug that wraps before functio...

Jon Phillips via All-commits all-commits at lists.llvm.org
Wed Aug 23 11:18:41 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d06b923915137c86e9f281e7fce28240e13665ea
      https://github.com/llvm/llvm-project/commit/d06b923915137c86e9f281e7fce28240e13665ea
  Author: Jon Phillips <jonap2811 at gmail.com>
  Date:   2023-08-23 (Wed, 23 Aug 2023)

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

  Log Message:
  -----------
  [clang-format] Fix a bug that wraps before function arguments

Fixes a long-standing bug that erroneously placed function arguments on a
new line despite all arguments being able to fit on the same line.

The original diff that introduced the bug implemented behaviour that pushed
the first argument to a function onto a new line under certain circumstances
relating passing lambdas as arguments.

This behaviour was implemented in TokenAnnotator::mustBreakBefore() which
meant the code lacked the necessary context to figure out whether subsequent
arguments might be able to all fit on one line. As such, I've moved the
implementation to ContinuationIndenter and, instead of forcing a line break
at the first argument in all cases, we now allow the OptimizingLineFormatter
to consider placing the first argument on the same line as the function call
but don't allow further line breaks in this case.

The end result is that either the first argument must go on a new line (as
before) or all arguments must be put on the current line.

Closes #44486.

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




More information about the All-commits mailing list