[clang] [clang-format] Handle template closer followed by braces (PR #110971)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 3 01:59:26 PDT 2024
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/110971
Fixes #110968.
>From b98834264b09fb283cc060ee06576b014809ec5f Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Thu, 3 Oct 2024 01:57:14 -0700
Subject: [PATCH] [clang-format] Handle template closer followed by braces
Fixes #110968.
---
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 a38a86764d68c5..9c4a065fd93b96 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 de1346b5ddd5a7..27ae7115dbe0e2 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3538,6 +3538,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 cfe-commits
mailing list