[PATCH] D113319: [clang-format] Improve require and concept handling
Björn Schäpers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 22 11:35:52 PST 2022
HazardyKnusperkeks added a comment.
In D113319#3337680 <https://reviews.llvm.org/D113319#3337680>, @curdeius wrote:
> In D113319#3337612 <https://reviews.llvm.org/D113319#3337612>, @krasimir wrote:
>
>> It appears that this causes a regression by adding a space in-between pointer dereferences `*p` -> `* p` in some cases, e.g. formatting this with llvm style:
>>
>> // before
>> void f() {
>> while (p < a && *p == 'a')
>> p++;
>> }
>> // after
>> void f() {
>> while (p < a && * p == 'a')
>> p++;
>> }
>
> `*` in `*p` is indeed annotated as a binary operator now:
>
> clang-format-main-20220110-5ff916ab72b26e667bd5d2e4a762650ba479c781--style=file --debug-only=format-token-annotator test.cpp
> AnnotatedTokens(L=0):
> M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=while L=5 PPK=2 FakeLParens= FakeRParens=0 II=0x2f4bf80a6a0 Text='while'
> M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=23 Name=l_paren L=7 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
> M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=59 Name=identifier L=8 PPK=2 FakeLParens=10/5/ FakeRParens=0 II=0x2f4bf806fd8 Text='p'
> M=0 C=0 T=BinaryOperator S=1 F=0 B=0 BK=0 P=50 Name=less L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='<'
> M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=50 Name=identifier L=12 PPK=2 FakeLParens= FakeRParens=1 II=0x2f4bf807008 Text='q'
> M=0 C=0 T=BinaryOperator S=1 F=0 B=0 BK=0 P=45 Name=ampamp L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='&&'
> M=0 C=1 T=UnaryOperator S=1 F=0 B=0 BK=0 P=45 Name=star L=17 PPK=2 FakeLParens=0/ FakeRParens=0 II=0x0 Text='*'
> M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=100 Name=identifier L=18 PPK=2 FakeLParens= FakeRParens=2 II=0x2f4bf806fd8 Text='p'
> M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
> ----
> AnnotatedTokens(L=1):
> M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=semi L=1 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'
> ----
> AnnotatedTokens(L=0):
> M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=eof L=0 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=''
> ----
> while (p < q && *p)
> ;
>
> whereas it was (correctly) a unary operator:
>
> clang-format-main-20220222-e0219872--style=file --debug-only=format-token-annotator test.cpp
> AnnotatedTokens(L=0):
> M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=while L=5 PPK=2 FakeLParens= FakeRParens=0 II=0x23639666fa0 Text='while'
> M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=23 Name=l_paren L=7 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
> M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=59 Name=identifier L=8 PPK=2 FakeLParens=10/5/ FakeRParens=0 II=0x236396a30a0 Text='p'
> M=0 C=0 T=BinaryOperator S=1 F=0 B=0 BK=0 P=50 Name=less L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='<'
> M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=50 Name=identifier L=12 PPK=2 FakeLParens= FakeRParens=1 II=0x236396a30d0 Text='q'
> M=0 C=0 T=BinaryOperator S=1 F=0 B=0 BK=0 P=45 Name=ampamp L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='&&'
> M=0 C=1 T=BinaryOperator S=1 F=0 B=0 BK=0 P=45 Name=star L=17 PPK=2 FakeLParens=14/ FakeRParens=0 II=0x0 Text='*'
> M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=54 Name=identifier L=19 PPK=2 FakeLParens= FakeRParens=2 II=0x236396a30a0 Text='p'
> M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=20 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
> ----
> AnnotatedTokens(L=1):
> M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=semi L=1 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'
> ----
> AnnotatedTokens(L=0):
> M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=eof L=0 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=''
> ----
> while (p < q && * p)
> ;
That means someone guesses this is a binary op and guesses wrong. I try to take a look at it.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113319/new/
https://reviews.llvm.org/D113319
More information about the cfe-commits
mailing list