[clang] 67f576f - [clang-format] Handle template opener/closer in braced list (#112494)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 17 19:56:13 PDT 2024
Author: Owen Pan
Date: 2024-10-17T19:56:09-07:00
New Revision: 67f576f31d661897c5da302b8611decb7e0f9237
URL: https://github.com/llvm/llvm-project/commit/67f576f31d661897c5da302b8611decb7e0f9237
DIFF: https://github.com/llvm/llvm-project/commit/67f576f31d661897c5da302b8611decb7e0f9237.diff
LOG: [clang-format] Handle template opener/closer in braced list (#112494)
Fixes #112487.
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 c9625c39e527b4..bda9850670ab06 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2504,6 +2504,11 @@ bool UnwrappedLineParser::parseBracedList(bool IsAngleBracket, bool IsEnum) {
// Assume there are no blocks inside a braced init list apart
// from the ones we explicitly parse out (like lambdas).
FormatTok->setBlockKind(BK_BracedInit);
+ if (!IsAngleBracket) {
+ auto *Prev = FormatTok->Previous;
+ if (Prev && Prev->is(tok::greater))
+ Prev->setFinalizedType(TT_TemplateCloser);
+ }
nextToken();
parseBracedList();
break;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 00776dac28a14b..60deae0c9b1129 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3554,6 +3554,12 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
ASSERT_EQ(Tokens.size(), 21u) << Tokens;
EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener);
EXPECT_TOKEN(Tokens[16], tok::greater, TT_TemplateCloser);
+
+ Tokens =
+ annotate("auto x{std::conditional_t<T::value == U::value, T, U>{}};");
+ ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+ EXPECT_TOKEN(Tokens[6], tok::less, TT_TemplateOpener);
+ EXPECT_TOKEN(Tokens[18], tok::greater, TT_TemplateCloser);
}
} // namespace
More information about the cfe-commits
mailing list