[PATCH] D140843: [clang-format] fix template closer followed by >
Zhikai Zeng via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 4 05:21:55 PST 2023
Backl1ght updated this revision to Diff 486248.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140843/new/
https://reviews.llvm.org/D140843
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -339,6 +339,14 @@
EXPECT_TOKEN(Tokens[19], tok::greater, TT_TemplateCloser);
}
+TEST_F(TokenAnnotatorTest, UnderstandsGreaterAfterTemplateCloser) {
+ auto Tokens = annotate("if (std::tuple_size_v<T> > 0)");
+ ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+ EXPECT_TOKEN(Tokens[5], tok::less, TT_TemplateOpener);
+ EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+ EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
+}
+
TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
FormatStyle Style = getLLVMStyle();
Style.WhitespaceSensitiveMacros.push_back("FOO");
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10341,6 +10341,8 @@
verifyFormat("bool_constant<a && noexcept(f())>");
verifyFormat("bool_constant<a || noexcept(f())>");
+ verifyFormat("if (std::tuple_size_v<T> > 0)");
+
// Not template parameters.
verifyFormat("return a < b && c > d;");
verifyFormat("void f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -166,10 +166,9 @@
// parameter cases, but should not alter program semantics.
if (CurrentToken->Next && CurrentToken->Next->is(tok::greater) &&
Left->ParentBracket != tok::less &&
- (isKeywordWithCondition(*Line.First) ||
- CurrentToken->getStartOfNonWhitespace() ==
- CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
- -1))) {
+ CurrentToken->getStartOfNonWhitespace() ==
+ CurrentToken->Next->getStartOfNonWhitespace().getLocWithOffset(
+ -1)) {
return false;
}
Left->MatchingParen = CurrentToken;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140843.486248.patch
Type: text/x-patch
Size: 2188 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230104/b8fe49fa/attachment.bin>
More information about the cfe-commits
mailing list