[clang] 777b6ad - [clang-format] Handle return type auto followed by l_paren

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 17 16:06:45 PDT 2022


Author: owenca
Date: 2022-08-17T16:06:34-07:00
New Revision: 777b6ad168a07d1116fc0488f959b494d06f7f29

URL: https://github.com/llvm/llvm-project/commit/777b6ad168a07d1116fc0488f959b494d06f7f29
DIFF: https://github.com/llvm/llvm-project/commit/777b6ad168a07d1116fc0488f959b494d06f7f29.diff

LOG: [clang-format] Handle return type auto followed by l_paren

Fixes #57160.

Differential Revision: https://reviews.llvm.org/D132008

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 5ea1506bae193..b4694a59a89e2 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3337,9 +3337,11 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   }
 
   // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
-  if (Left.is(tok::kw_auto) &&
-      Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace))
+  if (Left.is(tok::kw_auto) && Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace,
+                                             // function return type 'auto'
+                                             TT_FunctionTypeLParen)) {
     return true;
+  }
 
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index dc450029ccc2d..c3264e7cf84a2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24887,7 +24887,7 @@ TEST_F(FormatTest, FormatDecayCopy) {
                                 // the user's own fault
   verifyFormat("integral auto(x) = y;"); // actually a declaration, but this is
                                          // clearly the user's own fault
-  verifyFormat("auto(*p)() = f;");       // actually a declaration; TODO FIXME
+  verifyFormat("auto (*p)() = f;");
 }
 
 TEST_F(FormatTest, Cpp20ModulesSupport) {


        


More information about the cfe-commits mailing list