[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 13:44:07 PDT 2019


lichray added inline comments.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:1354
+  static bool isDeductionGuide(FormatToken &Current) {
+    // Look for a deduction guide A()...) -> A<...>;
+    if (Current.Previous && Current.Previous->is(tok::r_paren) &&
----------------
Parentheses not matching is comment.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:1365
+        if (TemplateCloser->is(tok::greater))
+          NestingLevel--;
+        if (TemplateCloser->is(tok::kw_decltype))
----------------
Does this work?  What about `A() -> A<(3 < 2)>;`?


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:1366
+          NestingLevel--;
+        if (TemplateCloser->is(tok::kw_decltype))
+          return false;
----------------
What's this for?  What about `A() -> A<sizeof(p->foo<1>>);`

I guess we don't have to look for the end of template, because a class X can't refer to its member called X with `->` because that member is constructor.  The approach to match the identifiers may not work in the future but may work fine for now.


================
Comment at: clang/unittests/Format/FormatTest.cpp:4992
+  verifyFormat("x = p->foo<3>();");
+  verifyFormat("A()->A<decltype(p->foo<3>())>;");
+}
----------------
This looks like a deduction guide.  It should be formatted as `A() -> A<decltype(p->foo<3>())>;` I assume?  If you cannot cover this case in this patch, this test case needs a comment.


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

https://reviews.llvm.org/D69577





More information about the cfe-commits mailing list