@@ -1329,24 +1329,25 @@ FormatToken *FormatTokenLexer::getNextToken() {
1329
1329
if (FormatTok->is (tok::unknown))
1330
1330
FormatTok->setType (TT_ImplicitStringLiteral);
1331
1331
1332
+ const bool IsCpp = Style.isCpp ();
1333
+
1332
1334
// JavaScript and Java do not allow to escape the end of the line with a
1333
1335
// backslash. Backslashes are syntax errors in plain source, but can occur in
1334
1336
// comments. When a single line comment ends with a \, it'll cause the next
1335
1337
// line of code to be lexed as a comment, breaking formatting. The code below
1336
1338
// finds comments that contain a backslash followed by a line break, truncates
1337
1339
// the comment token at the backslash, and resets the lexer to restart behind
1338
1340
// the backslash.
1339
- if ((Style.isCpp () || Style.isJavaScript () || Style.isJava ()) &&
1340
- FormatTok->is (tok::comment)) {
1341
- if (const auto Text = FormatTok->TokenText ; Text.starts_with (" //" )) {
1342
- for (auto Pos = Text.find (' \\ ' ); Pos++ != StringRef::npos;
1343
- Pos = Text.find (' \\ ' , Pos)) {
1344
- if (Pos < Text.size () && Text[Pos] == ' \n ' &&
1345
- (!Style.isCpp () ||
1346
- Text.substr (Pos + 1 ).ltrim ().starts_with (" //" ))) {
1347
- truncateToken (Pos);
1348
- break ;
1349
- }
1341
+ if (const auto Text = FormatTok->TokenText ;
1342
+ Text.starts_with (" //" ) &&
1343
+ (IsCpp || Style.isJavaScript () || Style.isJava ())) {
1344
+ assert (FormatTok->is (tok::comment));
1345
+ for (auto Pos = Text.find (' \\ ' ); Pos++ != StringRef::npos;
1346
+ Pos = Text.find (' \\ ' , Pos)) {
1347
+ if (Pos < Text.size () && Text[Pos] == ' \n ' &&
1348
+ (!IsCpp || Text.substr (Pos + 1 ).ltrim ().starts_with (" //" ))) {
1349
+ truncateToken (Pos);
1350
+ break ;
1350
1351
}
1351
1352
}
1352
1353
}
@@ -1452,7 +1453,7 @@ FormatToken *FormatTokenLexer::getNextToken() {
1452
1453
Column = FormatTok->LastLineColumnWidth ;
1453
1454
}
1454
1455
1455
- if (Style. isCpp () ) {
1456
+ if (IsCpp ) {
1456
1457
auto *Identifier = FormatTok->Tok .getIdentifierInfo ();
1457
1458
auto it = Macros.find (Identifier);
1458
1459
if ((Tokens.empty () || !Tokens.back ()->Tok .getIdentifierInfo () ||
0 commit comments