-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Description
.clang_format:
OneLineFormatOffRegex: MACRO_TESTtest.cpp:
int main() {
MACRO_TEST();
MACRO_TEST();
MACRO_TEST();
MACRO_TEST();
MACRO_TEST();
}Running
clang-format-21 -i --style=file:.clang_format test.cpp
Results in the following incorrectly formatted output:
int main() {
MACRO_TEST();
MACRO_TEST();
MACRO_TEST();
MACRO_TEST();
MACRO_TEST();
}It seems like if we previously skipped formatting a line, then the first token of the next line is skipped from the regex match check. In the example, since the only matching token is the first in the line, we get this behavior. This doesn't occur if the token matching is at the EOL.
When transitioning from FO_CurrentLine (or FO_NextLine) to FO_None, the code breaks immediately, so the current token never gets evaluated against the regex in the default case.
https://github.com/llvm/llvm-project/pull/137577/files#diff-8e6ad02b15a65cc2ff3b2e622d25b2b45e8e900f54ce9ee79026d76115076a5eR93-R98
I think a possible solution to this would be

Also instead of evaluateCurrentToken you might also be able to look for !Tok.Finalized but I haven't read through enough of the code to confirm.
Metadata
Metadata
Assignees
Type
Projects
Status