Skip to content

Commit 72d6d6e

Browse files
authored
[clang-format] Fix a bug in OneLineFormatOffRegex (#162961)
Fixes #162402
1 parent 4b8cac2 commit 72d6d6e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ ArrayRef<FormatToken *> FormatTokenLexer::lex() {
9393
auto &Tok = *Tokens.back();
9494
const auto NewlinesBefore = Tok.NewlinesBefore;
9595
switch (FormatOff) {
96-
case FO_CurrentLine:
97-
if (NewlinesBefore == 0)
98-
Tok.Finalized = true;
99-
else
100-
FormatOff = FO_None;
101-
break;
10296
case FO_NextLine:
10397
if (NewlinesBefore > 1) {
10498
FormatOff = FO_None;
@@ -107,6 +101,13 @@ ArrayRef<FormatToken *> FormatTokenLexer::lex() {
107101
FormatOff = FO_CurrentLine;
108102
}
109103
break;
104+
case FO_CurrentLine:
105+
if (NewlinesBefore == 0) {
106+
Tok.Finalized = true;
107+
break;
108+
}
109+
FormatOff = FO_None;
110+
[[fallthrough]];
110111
default:
111112
if (!FormattingDisabled && FormatOffRegex.match(Tok.TokenText)) {
112113
if (Tok.is(tok::comment) &&

clang/unittests/Format/FormatTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24843,6 +24843,11 @@ TEST_F(FormatTest, OneLineFormatOffRegex) {
2484324843
" } while (0 )",
2484424844
Style);
2484524845

24846+
Style.OneLineFormatOffRegex = "MACRO_TEST";
24847+
verifyNoChange(" MACRO_TEST1 ( ) ;\n"
24848+
" MACRO_TEST2( );",
24849+
Style);
24850+
2484624851
Style.ColumnLimit = 50;
2484724852
Style.OneLineFormatOffRegex = "^LogErrorPrint$";
2484824853
verifyFormat(" myproject::LogErrorPrint(logger, \"Don't split me!\");\n"

0 commit comments

Comments
 (0)