-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang-format generates extra trailing spaces in the last line with InsertNewlineAtEOF enabled #108333
Comments
How did you run clang-format? |
Like google/vim-codefmt#217 mentioned, I use https://github.com/google/vim-codefmt with Vim to format the code. The plugin passes the buffer content to clang-format and replace the whole buffer. I've narrowed down the issue to the minimal reproducible example in #108333 (comment). The key point is that the last line does not contain Another one-line example:
|
@llvm/issue-subscribers-bug Author: Kevin Lin (kevinptt0323)
clang-format generates extra trailing spaces in the last line when the following three statements are true:
Minimal reproducible example: $ clang-format --version
Ubuntu clang-format version 18.1.3 (1ubuntu1)
$ cat test.cpp
namespace foo {
int bar;
} // namespace foo$ xxd test.cpp
00000000: 6e61 6d65 7370 6163 6520 666f 6f20 7b0a namespace foo {.
00000010: 696e 7420 6261 723b 0a7d 202f 2f20 6e61 int bar;.} // na
00000020: 6d65 7370 6163 6520 666f 6f mespace foo
$ clang-format -style '{InsertNewlineAtEOF: true}' test.cpp -lines 1:3 | xxd
00000000: 6e61 6d65 7370 6163 6520 666f 6f20 7b0a namespace foo {.
00000010: 696e 7420 6261 723b 0a7d 202f 2f20 6e61 int bar;.} // na
00000020: 6d65 7370 6163 6520 666f 6f0a 2020 2020 mespace foo.
00000030: 2020 2020 2020 2020 2020 2020 2020
$ clang-format -style '{InsertNewlineAtEOF: true}' test.cpp | xxd
00000000: 6e61 6d65 7370 6163 6520 666f 6f20 7b0a namespace foo {.
00000010: 696e 7420 6261 723b 0a7d 202f 2f20 6e61 int bar;.} // na
00000020: 6d65 7370 6163 6520 666f 6f0a mespace foo.
$ clang-format -style '{InsertNewlineAtEOF: false}' test.cpp -lines 1:3 | xxd
00000000: 6e61 6d65 7370 6163 6520 666f 6f20 7b0a namespace foo {.
00000010: 696e 7420 6261 723b 0a7d 202f 2f20 6e61 int bar;.} // na
00000020: 6d65 7370 6163 6520 666f 6f mespace foo |
/cherry-pick 7153a4b |
Fixes llvm#108333. (cherry picked from commit 7153a4b)
/pull-request #109170 |
Fixes llvm#108333. (cherry picked from commit 7153a4b)
clang-format generates extra trailing spaces in the last line when the following three statements are true:
InsertNewlineAtEOF
is true.EOL
(0x0a
)-lines
is specifiedMinimal reproducible example:
The text was updated successfully, but these errors were encountered: