https://github.com/dty2 updated https://github.com/llvm/llvm-project/pull/120904
From f36a48a92999cb791bf79b79adddaa73cab6f135 Mon Sep 17 00:00:00 2001 From: hunter <284050...@qq.com> Date: Mon, 23 Dec 2024 00:35:30 +0800 Subject: [PATCH 1/2] [Clang] Repair the functionrParenEndsCast to make incorrect judgments in template variable cases --- clang/lib/Format/TokenAnnotator.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index f2cfa7f49f62f9..fa9751cc8a7d92 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -38,6 +38,9 @@ static bool mustBreakAfterAttributes(const FormatToken &Tok, namespace { +SmallVector<llvm::StringRef, 100> castIdentifiers{"__type_identity_t", + "remove_reference_t"}; + /// Returns \c true if the line starts with a token that can start a statement /// with an initializer. static bool startsWithInitStatement(const AnnotatedLine &Line) { @@ -2474,6 +2477,9 @@ class AnnotatingParser { Current.getNextNonComment()->isOneOf(tok::comma, tok::r_brace)) { Current.setType(TT_StringInConcatenation); } + } else if (Current.is(tok::kw_using)) { + if (Current.Next->Next->Next->isTypeName(LangOpts)) + castIdentifiers.push_back(Current.Next->TokenText); } else if (Current.is(tok::l_paren)) { if (lParenStartsCppCast(Current)) Current.setType(TT_CppCastLParen); @@ -2831,8 +2837,18 @@ class AnnotatingParser { IsQualifiedPointerOrReference(BeforeRParen, LangOpts); bool ParensCouldEndDecl = AfterRParen->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater); - if (ParensAreType && !ParensCouldEndDecl) + if (ParensAreType && !ParensCouldEndDecl) { + if (BeforeRParen->is(TT_TemplateCloser)) { + auto *Prev = BeforeRParen->MatchingParen->getPreviousNonComment(); + if (Prev) { + for (auto &name : castIdentifiers) + if (Prev->TokenText == name) + return true; + return false; + } + } return true; + } // At this point, we heuristically assume that there are no casts at the // start of the line. We assume that we have found most cases where there From 3cdd6fddfbdbf5a27fa2c6cf3c26c57435c78b70 Mon Sep 17 00:00:00 2001 From: hunter <284050...@qq.com> Date: Mon, 23 Dec 2024 01:55:15 +0800 Subject: [PATCH 2/2] [Clang] Repair the functionrParenEndsCast to make incorrect judgments in template variable cases --- clang/lib/Format/TokenAnnotator.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index fa9751cc8a7d92..ccf18bbdea84e0 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -38,6 +38,7 @@ static bool mustBreakAfterAttributes(const FormatToken &Tok, namespace { +// TODO: Add new Type modifiers SmallVector<llvm::StringRef, 100> castIdentifiers{"__type_identity_t", "remove_reference_t"}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits