[clang] 4701bca - Revert "[clang-format] Avoid inserting space after C++ casts."

Marek Kurdej via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 20 13:19:57 PST 2022


Author: Marek Kurdej
Date: 2022-02-20T22:19:51+01:00
New Revision: 4701bcae974704a336ac8e111d5b104f4834099c

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

LOG: Revert "[clang-format] Avoid inserting space after C++ casts."

This reverts commit e021987273bece6e94bc6f43b6b5232de10637c8.

This commit provokes failures in formatting tests of polly.
Cf. https://lab.llvm.org/buildbot/#/builders/205/builds/3320.

That's probably because of `)` being annotated as `CastRParen` instead of `Unknown` before, hence being kept on the same line with the next token.

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 51e7c32b7d4c7..9a020eb6ca7dc 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1734,11 +1734,8 @@ class AnnotatingParser {
       else
         Current.setType(TT_LineComment);
     } else if (Current.is(tok::r_paren)) {
-      if (rParenEndsCast(Current)) {
+      if (rParenEndsCast(Current))
         Current.setType(TT_CastRParen);
-        assert(Current.MatchingParen);
-        Current.MatchingParen->setType(TT_Unknown);
-      }
       if (Current.MatchingParen && Current.Next &&
           !Current.Next->isBinaryOperator() &&
           !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
@@ -1941,20 +1938,8 @@ class AnnotatingParser {
 
       // Certain other tokens right before the parentheses are also signals that
       // this cannot be a cast.
-      if (LeftOfParens->is(TT_TemplateCloser)) {
-        if (LeftOfParens->MatchingParen) {
-          auto *Prev = LeftOfParens->MatchingParen->getPreviousNonComment();
-          if (Prev &&
-              Prev->isOneOf(tok::kw_const_cast, tok::kw_dynamic_cast,
-                            tok::kw_reinterpret_cast, tok::kw_static_cast))
-            // FIXME: Maybe we should handle identifiers ending with "_cast",
-            // e.g. any_cast?
-            return true;
-        }
-        return false;
-      }
       if (LeftOfParens->isOneOf(tok::at, tok::r_square, TT_OverloadedOperator,
-                                tok::ellipsis))
+                                TT_TemplateCloser, tok::ellipsis))
         return false;
     }
 

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d45146d5242fb..f71f8dc5de456 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10565,13 +10565,6 @@ TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {
 
 TEST_F(FormatTest, FormatsCasts) {
   verifyFormat("Type *A = static_cast<Type *>(P);");
-  verifyFormat("static_cast<Type *>(P);");
-  verifyFormat("static_cast<Type &>(Fun)(Args);");
-  verifyFormat("static_cast<Type &>(*Fun)(Args);");
-  verifyFormat("a = static_cast<Type &>(*Fun)(Args);");
-  verifyFormat("const_cast<Type &>(*Fun)(Args);");
-  verifyFormat("dynamic_cast<Type &>(*Fun)(Args);");
-  verifyFormat("reinterpret_cast<Type &>(*Fun)(Args);");
   verifyFormat("Type *A = (Type *)P;");
   verifyFormat("Type *A = (vector<Type *, int *>)P;");
   verifyFormat("int a = (int)(2.0f);");


        


More information about the cfe-commits mailing list