llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-format] unexpected formatting on empty lines

Open kadircet opened this issue 1 year ago • 3 comments

command clang-format --lines=2:2 a.cc

actual formatting:

void f() {
  
}

expected formatting:

void f() {}

this seems to be WAI if there are tokens on line 2, e.g:

void f() {
  return;
}

gets formatted as void f() { return; }.

kadircet avatar May 07 '25 19:05 kadircet

@llvm/issue-subscribers-clang-format

Author: kadir çetinkaya (kadircet)

command `clang-format --lines=2:2 a.cc`

actual formatting:

void f() {
  
}

expected formatting:

void f() {}

this seems to be WAI if there are tokens on line 2, e.g:

void f() {
  return;
}

gets formatted as void f() { return; }.

llvmbot avatar May 07 '25 19:05 llvmbot

@llvm/issue-subscribers-c-1

Author: kadir çetinkaya (kadircet)

command `clang-format --lines=2:2 a.cc`

actual formatting:

void f() {
  
}

expected formatting:

void f() {}

this seems to be WAI if there are tokens on line 2, e.g:

void f() {
  return;
}

gets formatted as void f() { return; }.

llvmbot avatar May 07 '25 19:05 llvmbot

Here is a test repro.

TEST_F(FormatTestSelective, Repro) {
  EXPECT_EQ("void f() {}\n", format("void f() {\n  \n}\n", 13, 0));
}

tJener avatar Jun 24 '25 18:06 tJener