Skip to content

Commit ed80aca

Browse files
committed
Address review feedback
1 parent 1f54d83 commit ed80aca

File tree

3 files changed

+15
-29
lines changed

3 files changed

+15
-29
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,9 +1025,6 @@ clang-format
10251025
``enum`` enumerator lists.
10261026
- Add ``OneLineFormatOffRegex`` option for turning formatting off for one line.
10271027
- Add ``SpaceAfterOperatorKeyword`` option.
1028-
- Support trailing whitespace in line splicing.
1029-
(P2223R2 <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2223r2.pdf>_, #GH145226)
1030-
10311028

10321029
clang-refactor
10331030
--------------

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,25 +1204,22 @@ static size_t countLeadingWhitespace(StringRef Text) {
12041204
const unsigned char *const End = Text.bytes_end();
12051205
const unsigned char *Cur = Begin;
12061206
while (Cur < End) {
1207-
if (isspace(Cur[0])) {
1207+
if (isWhitespace(Cur[0])) {
12081208
++Cur;
12091209
} else if (Cur[0] == '\\') {
1210-
// A '\' followed by a optional horizontal whitespace (P22232R2) and then
1211-
// newline always escapes the newline, regardless of whether there is
1212-
// another '\' before it.
1210+
// A backslash followed by optional horizontal whitespaces (P22232R2) and
1211+
// then a newline always escapes the newline.
12131212
// The source has a null byte at the end. So the end of the entire input
12141213
// isn't reached yet. Also the lexer doesn't break apart an escaped
12151214
// newline.
1216-
const unsigned char *Lookahead = Cur + 1;
1215+
const auto *Lookahead = Cur + 1;
12171216
while (isHorizontalWhitespace(*Lookahead))
12181217
++Lookahead;
1219-
if (*Lookahead == '\n' || *Lookahead == '\r') {
1220-
// Splice found, consume it.
1221-
Cur = Lookahead + 1;
1222-
continue;
1223-
}
1224-
// No line splice found; the '\' is a token.
1225-
break;
1218+
// No line splice found; the backslash is a token.
1219+
if (!isVerticalWhitespace(*Lookahead))
1220+
break;
1221+
// Splice found, consume it.
1222+
Cur = Lookahead + 1;
12261223
} else if (Cur[0] == '?' && Cur[1] == '?' && Cur[2] == '/' &&
12271224
(Cur[3] == '\n' || Cur[3] == '\r')) {
12281225
// Newlines can also be escaped by a '?' '?' '/' trigraph. By the way, the

clang/unittests/Format/FormatTest.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25769,25 +25769,17 @@ TEST_F(FormatTest, OperatorPassedAsAFunctionPtr) {
2576925769
}
2577025770

2577125771
TEST_F(FormatTest, LineSpliceWithTrailingWhitespace) {
25772-
// Test that each sequence of a backslash (\) immediately followed by zero or
25773-
// more horizontal whitespace characters and then a new-line character is
25774-
// treated as a single logical line while formatting (as per P2223R2).
25775-
FormatStyle Style = getLLVMStyle();
25772+
auto Style = getLLVMStyle();
2577625773
Style.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
2577725774
Style.UseTab = FormatStyle::UT_Never;
2577825775

25779-
verifyFormat("int i;",
25780-
" \\ \n"
25781-
" int i;",
25782-
Style);
25783-
verifyFormat("#define FOO(args) \\\n struct a {};\n",
25776+
verifyFormat("int i;", " \\ \n"
25777+
" int i;");
25778+
verifyFormat("#define FOO(args) \\\n"
25779+
" struct a {};",
2578425780
"#define FOO( args ) \\ \n"
2578525781
"struct a{\\\t\t\t\n"
25786-
" };\n",
25787-
Style);
25788-
verifyFormat("comment here",
25789-
"comment \\ \n"
25790-
"here",
25782+
" };",
2579125783
Style);
2579225784
}
2579325785

0 commit comments

Comments
 (0)