[PATCH] D130299: [clang-format] FIX: Misannotation 'auto' as trailing return type in lambdas

Denis Fatkulin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 23 03:58:26 PDT 2022


denis-fatkulin updated this revision to Diff 447052.
denis-fatkulin retitled this revision from "[clang-format] FIX: Misformatting lambdas with trailing return type 'auto' in braced lists" to "[clang-format] FIX: Misannotation 'auto' as trailing return type in lambdas".
denis-fatkulin edited the summary of this revision.
denis-fatkulin added a comment.

Patch is splitted, as suggested by @HazardyKnusperkeks

This piece of changes is related to misannotation KW 'auto' as trailing return type in lambdas. Also, appropriate test is added.


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

https://reviews.llvm.org/D130299

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -749,6 +749,13 @@
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsTrailingReturnTypeAutoInLabmdas) {
+  auto Tokens = annotate("[]() -> auto {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_LambdaArrow);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_LambdaLBrace);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
     case tok::l_square:
       parseSquare();
       break;
+    case tok::kw_auto:
     case tok::kw_class:
     case tok::kw_template:
     case tok::kw_typename:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130299.447052.patch
Type: text/x-patch
Size: 1044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220723/0cda66ce/attachment.bin>


More information about the cfe-commits mailing list