[PATCH] D69577: [clang-format] [PR35518] C++17 deduction guides are wrongly formatted

Zhihao Yuan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 30 10:12:40 PDT 2019


lichray added inline comments.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:1400-1403
+    } else if (Current.Previous && Current.Previous->is(tok::r_paren) &&
+               Current.startsSequence(tok::arrow, tok::identifier, tok::less)) {
+      // Deduction guides trailing arrow "...) -> A<T>".
+      Current.Type = TT_TrailingReturnArrow;
----------------
MyDeveloperDay wrote:
> lichray wrote:
> > klimek wrote:
> > > Why doesn't this trigger on function templates:
> > >   c()->f<int>();
> > > 
> > Comparing to the `else if` branch above, several questions can arise:
> > 
> > 1. Has deduction-guide be considered a declaration (it is, of course, in standard)?  If yes, without `MustBeDeclaration`, how `x = p->foo<3>();` being formatted?
> > 2. Without restrictions on `NestingLevel`, how `A() -> A<decltype(p->foo<3>())>;` being formatted?
> > 3. How `x()->foo<1>;` being formatted?  What's the difference between this and a deduction-guide?  A deduction-guide has to follow `TheSameType(...) -> TheSameType<....>;` and appears only at namespace level, do these help?
> > 
> > Oh no, `auto x = p -> foo<1>();` this is a bug (I will look for bug reports, don't mind).
> This case I agree is wrong  (but that comes from the existing rule no?)
> ```
> auto x = p -> foo<1>();
> ```
> 
> The other examples are currently as follows
> ```
> c()->f<int>();
> x()->foo<1>;
> x = p->foo<3>();
> A()->A<decltype(p->foo<3>())>;
> ```
> 
> This is how they look from the last build @hans  made on the 17th October
> 
> ```
> auto x = p -> foo<1>();
> c()->f<int>();
> x()->foo<1>;
> x = p->foo<3>();
> A()->A<decltype(p->foo<3>())>;
> ```
> 
> Debug info
> 
> ```
> ----
> AnnotatedTokens(L=0):
>  M=0 C=0 T=Unknown S=1 B=0 BK=0 P=0 Name=auto L=4 PPK=2 FakeLParens=2/ FakeRParens=0 II=0x2c52129f718 Text='auto'
>  M=0 C=1 T=StartOfName S=1 B=0 BK=0 P=220 Name=identifier L=6 PPK=2 FakeLParens= FakeRParens=0 II=0x2c5212a2da8 Text='x'
>  M=0 C=0 T=BinaryOperator S=1 B=0 BK=0 P=22 Name=equal L=8 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='='
>  M=0 C=1 T=Unknown S=1 B=0 BK=0 P=22 Name=identifier L=10 PPK=2 FakeLParens=0/ FakeRParens=0 II=0x2c5212a2dd8 Text='p'
>  M=0 C=1 T=TrailingReturnArrow S=1 B=0 BK=0 P=23 Name=arrow L=13 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='->'
>  M=0 C=0 T=Unknown S=1 B=0 BK=0 P=23 Name=identifier L=17 PPK=2 FakeLParens= FakeRParens=0 II=0x2c5212a2d78 Text='foo'
>  M=0 C=0 T=TemplateOpener S=0 B=0 BK=0 P=30 Name=less L=18 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='<'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=360 Name=numeric_constant L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='1'
>  M=0 C=0 T=TemplateCloser S=0 B=0 BK=0 P=270 Name=greater L=20 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='>'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=30 Name=l_paren L=21 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=59 Name=r_paren L=22 PPK=2 FakeLParens= FakeRParens=2 II=0x0 Text=')'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=23 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'
> ----
> AnnotatedTokens(L=0):
>  M=0 C=0 T=Unknown S=1 B=0 BK=0 P=0 Name=identifier L=1 PPK=2 FakeLParens=0/ FakeRParens=0 II=0x2c5212a2e08 Text='c'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=l_paren L=2 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=140 Name=r_paren L=3 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=170 Name=arrow L=5 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='->'
>  M=0 C=0 T=TrailingAnnotation S=0 B=0 BK=0 P=190 Name=identifier L=6 PPK=2 FakeLParens= FakeRParens=0 II=0x2c5212a2d48 Text='f'
>  M=0 C=0 T=TemplateOpener S=0 B=0 BK=0 P=30 Name=less L=7 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='<'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=360 Name=int L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x2c52129fa50 Text='int'
>  M=0 C=0 T=TemplateCloser S=0 B=0 BK=0 P=270 Name=greater L=11 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='>'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=30 Name=l_paren L=12 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=140 Name=r_paren L=13 PPK=2 FakeLParens= FakeRParens=1 II=0x0 Text=')'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=14 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'
> ----
> AnnotatedTokens(L=0):
>  M=0 C=0 T=Unknown S=1 B=0 BK=0 P=0 Name=identifier L=1 PPK=2 FakeLParens=0/ FakeRParens=0 II=0x2c5212a2da8 Text='x'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=l_paren L=2 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=140 Name=r_paren L=3 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=170 Name=arrow L=5 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='->'
>  M=0 C=0 T=TrailingAnnotation S=0 B=0 BK=0 P=190 Name=identifier L=8 PPK=2 FakeLParens= FakeRParens=0 II=0x2c5212a2d78 Text='foo'
>  M=0 C=0 T=TemplateOpener S=0 B=0 BK=0 P=30 Name=less L=9 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='<'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=360 Name=numeric_constant L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='1'
>  M=0 C=0 T=TemplateCloser S=0 B=0 BK=0 P=270 Name=greater L=11 PPK=2 FakeLParens= FakeRParens=1 II=0x0 Text='>'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=30 Name=semi L=12 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'
> ----
> AnnotatedTokens(L=0):
>  M=0 C=0 T=Unknown S=1 B=0 BK=0 P=0 Name=identifier L=1 PPK=2 FakeLParens=2/ FakeRParens=0 II=0x2c5212a2da8 Text='x'
>  M=0 C=0 T=BinaryOperator S=1 B=0 BK=0 P=22 Name=equal L=3 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='='
>  M=0 C=1 T=Unknown S=1 B=0 BK=0 P=22 Name=identifier L=5 PPK=2 FakeLParens=0/ FakeRParens=0 II=0x2c5212a2dd8 Text='p'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=170 Name=arrow L=7 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='->'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=identifier L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x2c5212a2d78 Text='foo'
>  M=0 C=0 T=TemplateOpener S=0 B=0 BK=0 P=30 Name=less L=11 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='<'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=360 Name=numeric_constant L=12 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='3'
>  M=0 C=0 T=TemplateCloser S=0 B=0 BK=0 P=270 Name=greater L=13 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='>'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=30 Name=l_paren L=14 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=59 Name=r_paren L=15 PPK=2 FakeLParens= FakeRParens=2 II=0x0 Text=')'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=16 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'
> ----
> AnnotatedTokens(L=0):
>  M=0 C=0 T=Unknown S=1 B=0 BK=0 P=0 Name=identifier L=1 PPK=2 FakeLParens=0/ FakeRParens=0 II=0x2c5212a2cb8 Text='A'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=l_paren L=2 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=140 Name=r_paren L=3 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=170 Name=arrow L=5 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='->'
>  M=0 C=0 T=TrailingAnnotation S=0 B=0 BK=0 P=190 Name=identifier L=6 PPK=2 FakeLParens= FakeRParens=0 II=0x2c5212a2cb8 Text='A'
>  M=0 C=0 T=TemplateOpener S=0 B=0 BK=0 P=30 Name=less L=7 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='<'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=360 Name=decltype L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x2c5212a09f8 Text='decltype'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=263 Name=l_paren L=16 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=380 Name=identifier L=17 PPK=2 FakeLParens=0/ FakeRParens=0 II=0x2c5212a2dd8 Text='p'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=430 Name=arrow L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='->'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=283 Name=identifier L=22 PPK=2 FakeLParens= FakeRParens=0 II=0x2c5212a2d78 Text='foo'
>  M=0 C=0 T=TemplateOpener S=0 B=0 BK=0 P=290 Name=less L=23 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='<'
>  M=0 C=1 T=Unknown S=0 B=0 BK=0 P=620 Name=numeric_constant L=24 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='3'
>  M=0 C=0 T=TemplateCloser S=0 B=0 BK=0 P=530 Name=greater L=25 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='>'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=290 Name=l_paren L=26 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=400 Name=r_paren L=27 PPK=2 FakeLParens= FakeRParens=1 II=0x0 Text=')'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=283 Name=r_paren L=28 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
>  M=0 C=0 T=TemplateCloser S=0 B=0 BK=0 P=270 Name=greater L=29 PPK=2 FakeLParens= FakeRParens=1 II=0x0 Text='>'
>  M=0 C=0 T=Unknown S=0 B=0 BK=0 P=30 Name=semi L=30 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'
> ```
> 
> I should mention all existing unit tests pass, Beyonce rule!
New bug created: https://bugs.llvm.org/show_bug.cgi?id=43851


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69577/new/

https://reviews.llvm.org/D69577





More information about the cfe-commits mailing list