[clang] be5c3ca - Revert "[clang-format] Correctly recognize arrays in template parameter list."

Krasimir Georgiev via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 24 02:16:09 PDT 2022


Author: Krasimir Georgiev
Date: 2022-03-24T10:14:13+01:00
New Revision: be5c3ca7fbaec90fff004af54d3cd5f6c30a9664

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

LOG: Revert "[clang-format] Correctly recognize arrays in template parameter list."

This reverts commit 126b37a713dc1c67cbc7dc8b5288b2f907c906a9.

Regressed some ObjC patterns, see comments on https://reviews.llvm.org/D121584.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index b8cffcd471e91..c5594a6d66484 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1940,11 +1940,6 @@ bool UnwrappedLineParser::tryToParseLambda() {
   if (!tryToParseLambdaIntroducer())
     return false;
 
-  // `[something] >` is not a lambda, but an array type in a template parameter
-  // list.
-  if (FormatTok->is(tok::greater))
-    return false;
-
   bool SeenArrow = false;
   bool InTemplateParameterList = false;
 
@@ -3534,7 +3529,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
           // Don't try parsing a lambda if we had a closing parenthesis before,
           // it was probably a pointer to an array: int (*)[].
           if (!tryToParseLambda())
-            continue;
+            break;
         } else {
           parseSquare();
           continue;

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ac0802f837173..380ec90330f12 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -98,20 +98,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
   auto Tokens = annotate("struct S {};");
   EXPECT_EQ(Tokens.size(), 6u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_StructLBrace);
-
-  Tokens = annotate("template <typename T> struct S<const T[N]> {};");
-  EXPECT_EQ(Tokens.size(), 18u) << Tokens;
-  EXPECT_TOKEN(Tokens[7], tok::less, TT_TemplateOpener);
-  EXPECT_TOKEN(Tokens[10], tok::l_square, TT_ArraySubscriptLSquare);
-  EXPECT_TOKEN(Tokens[13], tok::greater, TT_TemplateCloser);
-  EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_StructLBrace);
-
-  Tokens = annotate("template <typename T> struct S<T const[N]> {};");
-  EXPECT_EQ(Tokens.size(), 18u) << Tokens;
-  EXPECT_TOKEN(Tokens[7], tok::less, TT_TemplateOpener);
-  EXPECT_TOKEN(Tokens[10], tok::l_square, TT_ArraySubscriptLSquare);
-  EXPECT_TOKEN(Tokens[13], tok::greater, TT_TemplateCloser);
-  EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_StructLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUnions) {


        


More information about the cfe-commits mailing list