owenpan updated this revision to Diff 425710.
owenpan added a comment.

Also checks the token before `*` and adds a test case.


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

https://reviews.llvm.org/D124589

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3336,6 +3336,14 @@
   verifyFormat("if (public == private)\n");
   verifyFormat("void foo(public, private)");
   verifyFormat("public::foo();");
+
+  verifyFormat("class A {\n"
+               "public:\n"
+               "  std::unique_ptr<int *[]> b() { return nullptr; }\n"
+               "\n"
+               "private:\n"
+               "  int c;\n"
+               "};");
 }
 
 TEST_F(FormatTest, SeparatesLogicalBlocks) {
@@ -21487,6 +21495,7 @@
                "  bar([]() {} // Did not respect 
SpacesBeforeTrailingComments\n"
                "  );\n"
                "}");
+  verifyFormat("auto k = *[](int *j) { return j; }(&i)");
 
   // Lambdas created through weird macros.
   verifyFormat("void f() {\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2037,13 +2037,17 @@
 
 bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
   const FormatToken *Previous = FormatTok->Previous;
-  if (Previous &&
-      (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
-                         tok::kw_delete, tok::l_square) ||
-       FormatTok->isCppStructuredBinding(Style) || Previous->closesScope() ||
-       Previous->isSimpleTypeSpecifier())) {
-    nextToken();
-    return false;
+  if (Previous) {
+    const FormatToken *PrevPrev = Previous->Previous;
+    if (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
+                          tok::kw_delete, tok::l_square) ||
+        FormatTok->isCppStructuredBinding(Style) || Previous->closesScope() ||
+        Previous->isSimpleTypeSpecifier() ||
+        (Previous->is(tok::star) && PrevPrev &&
+         PrevPrev->isSimpleTypeSpecifier())) {
+      nextToken();
+      return false;
+    }
   }
   nextToken();
   if (FormatTok->is(tok::l_square))


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3336,6 +3336,14 @@
   verifyFormat("if (public == private)\n");
   verifyFormat("void foo(public, private)");
   verifyFormat("public::foo();");
+
+  verifyFormat("class A {\n"
+               "public:\n"
+               "  std::unique_ptr<int *[]> b() { return nullptr; }\n"
+               "\n"
+               "private:\n"
+               "  int c;\n"
+               "};");
 }
 
 TEST_F(FormatTest, SeparatesLogicalBlocks) {
@@ -21487,6 +21495,7 @@
                "  bar([]() {} // Did not respect SpacesBeforeTrailingComments\n"
                "  );\n"
                "}");
+  verifyFormat("auto k = *[](int *j) { return j; }(&i)");
 
   // Lambdas created through weird macros.
   verifyFormat("void f() {\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2037,13 +2037,17 @@
 
 bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
   const FormatToken *Previous = FormatTok->Previous;
-  if (Previous &&
-      (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
-                         tok::kw_delete, tok::l_square) ||
-       FormatTok->isCppStructuredBinding(Style) || Previous->closesScope() ||
-       Previous->isSimpleTypeSpecifier())) {
-    nextToken();
-    return false;
+  if (Previous) {
+    const FormatToken *PrevPrev = Previous->Previous;
+    if (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new,
+                          tok::kw_delete, tok::l_square) ||
+        FormatTok->isCppStructuredBinding(Style) || Previous->closesScope() ||
+        Previous->isSimpleTypeSpecifier() ||
+        (Previous->is(tok::star) && PrevPrev &&
+         PrevPrev->isSimpleTypeSpecifier())) {
+      nextToken();
+      return false;
+    }
   }
   nextToken();
   if (FormatTok->is(tok::l_square))
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to