llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.13k stars 11.62k forks source link

clang-format: strange results with 5+ character upper-case return type #60136

Open h57624paen opened 1 year ago

h57624paen commented 1 year ago

Using clang-format 15.06 (on Windows if it matters) with an empty .clangformat file:

input:

A
a(int test) { return 1; }

AA
a(int test) { return 1; }

AAA
a(int test) { return 1; }

AAAA
a(int test) { return 1; }

/*clang-format will leave AAAAA on its own line*/
AAAAA
a(int test) { return 1; }

AAAAa
a(int test) { return 1; }

Post format:

A a(int test) { return 1; }

AA a(int test) { return 1; }

AAA a(int test) { return 1; }

AAAA a(int test) { return 1; }

/*clang-format will leave AAAAA on its own line*/
AAAAA
a(int test) { return 1; }

AAAAa a(int test) { return 1; }

AAaAA a(int test) { return 1; }

aaaAa a(int test) { return 1; }
llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-format

rymiel commented 1 year ago

Note that this is somewhat intended:

https://github.com/llvm/llvm-project/blob/83d56fb17a4d78471125df4249c3557bd4ddb5c2/clang/lib/Format/UnwrappedLineParser.cpp#L2068-L2074

This functionality has been in clang-format since its early days, as in, 10 years ago: https://github.com/llvm/llvm-project/commit/40e1921f2a33a7b9e9647de195274341b7779bf0. It probably does harken back to a time where clang-format was less configurable, though.