[llvm-branch-commits] [clang] release/19.x: [clang-format] Handle template closer followed by braces (#110971) (PR #111958)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 11 00:12:13 PDT 2024
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/111958
Backport e5b05a51b8151cc7788bbdea4d491e5ccfceedea
Requested by: @owenca
>From c1946eec57dcc901211a7464e7893098cb252d50 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Fri, 4 Oct 2024 18:18:03 -0700
Subject: [PATCH] [clang-format] Handle template closer followed by braces
(#110971)
Fixes #110968.
(cherry picked from commit e5b05a51b8151cc7788bbdea4d491e5ccfceedea)
---
clang/lib/Format/UnwrappedLineParser.cpp | 5 +++++
clang/unittests/Format/TokenAnnotatorTest.cpp | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index f7b3561f6e0335..631c7c62baac18 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2131,6 +2131,11 @@ void UnwrappedLineParser::parseStructuralElement(
return;
}
break;
+ case tok::greater:
+ nextToken();
+ if (FormatTok->is(tok::l_brace))
+ FormatTok->Previous->setFinalizedType(TT_TemplateCloser);
+ break;
default:
nextToken();
break;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 2f09b380a87134..6f3ef3b646c619 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3399,6 +3399,11 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);
+
+ Tokens = annotate("return std::conditional_t<T::value == U::value, T, U>{};");
+ ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+ EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener);
+ EXPECT_TOKEN(Tokens[16], tok::greater, TT_TemplateCloser);
}
} // namespace
More information about the llvm-branch-commits
mailing list