diff options
author | Naveen Seth Hanig <naveen.hanig@outlook.com> | 2025-06-25 09:13:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-25 18:13:00 +0200 |
commit | dd47b845a62cdaf4a1b0aba354cd80a4eabd9570 (patch) | |
tree | db42d57fff968c972928473d7d48271ebe2c65e0 /clang/unittests/Format | |
parent | 9a7720ad2f96fc5911be3ed2c53ec2bdf6fbd9a6 (diff) | |
download | llvm-dd47b845a62cdaf4a1b0aba354cd80a4eabd9570.zip llvm-dd47b845a62cdaf4a1b0aba354cd80a4eabd9570.tar.gz llvm-dd47b845a62cdaf4a1b0aba354cd80a4eabd9570.tar.bz2 |
[clang-format] Handle Trailing Whitespace After Line Continuation (P2223R2) (#145243)
Fixes #145226.
Implement
[P2223R2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2223r2.pdf)
in clang-format to correctly handle cases where a backslash '\\' is
followed by trailing whitespace before the newline.
Previously, `clang-format` failed to properly detect and handle such
cases, leading to misformatted code.
With this, `clang-format` matches the behavior already implemented in
Clang's lexer and `DependencyDirectivesScanner.cpp`, which allow
trailing whitespace after a line continuation in any C++ standard.
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index c0633ba..a05bf83 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -25768,6 +25768,21 @@ TEST_F(FormatTest, OperatorPassedAsAFunctionPtr) { verifyFormat("foo(operator, , -42);", Style); } +TEST_F(FormatTest, LineSpliceWithTrailingWhitespace) { + auto Style = getLLVMStyle(); + Style.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign; + Style.UseTab = FormatStyle::UT_Never; + + verifyFormat("int i;", " \\ \n" + " int i;"); + verifyFormat("#define FOO(args) \\\n" + " struct a {};", + "#define FOO( args ) \\ \n" + "struct a{\\\t\t\t\n" + " };", + Style); +} + TEST_F(FormatTest, WhitespaceSensitiveMacros) { FormatStyle Style = getLLVMStyle(); Style.WhitespaceSensitiveMacros.push_back("FOO"); |