| Issue |
162402
|
| Summary |
[clang-format] Bug `OneLineFormatOffRegex` broken if regex matches on first token
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
sebastianmueller01
|
@owenca
`.clang_format`:
```yml
OneLineFormatOffRegex: MACRO_TEST
```
test.cpp:
```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:
```cpp
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
<img width="1360" height="1148" alt="Image" src="" />
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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs